r72423 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72422‎ | r72423 | r72424 >
Date:13:20, 5 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - copied criteria validation functions over to new criteria classes
Modified paths:
  • /trunk/extensions/Validator/includes/ParameterCriterion.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionIsFloat.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionIsInteger.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionIsNumeric.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionMatchesRegex.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionNotEmpty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/criteria/CriterionIsNumeric.php
@@ -26,7 +26,7 @@
2727 * @see ParameterCriterion::validate
2828 */
2929 public function validate( $value ) {
30 -
 30+ return is_numeric( $value );
3131 }
3232
3333 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/criteria/CriterionMatchesRegex.php
@@ -14,19 +14,32 @@
1515 class CriterionMatchesRegex extends ParameterCriterion {
1616
1717 /**
 18+ * The pattern to match against.
 19+ *
 20+ * @since 0.4
 21+ *
 22+ * @var string
 23+ */
 24+ protected $pattern;
 25+
 26+ /**
1827 * Constructor.
1928 *
 29+ * @param string $pattern
 30+ *
2031 * @since 0.4
2132 */
22 - public function __construct( ) {
 33+ public function __construct( $pattern ) {
2334 parent::__construct();
 35+
 36+ $this->pattern = $pattern;
2437 }
2538
2639 /**
2740 * @see ParameterCriterion::validate
2841 */
2942 public function validate( $value ) {
30 -
 43+ return (bool)preg_match( $this->pattern, $value );
3144 }
3245
3346 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/criteria/CriterionNotEmpty.php
@@ -18,7 +18,7 @@
1919 *
2020 * @since 0.4
2121 */
22 - public function __construct( ) {
 22+ public function __construct() {
2323 parent::__construct();
2424 }
2525
@@ -26,7 +26,7 @@
2727 * @see ParameterCriterion::validate
2828 */
2929 public function validate( $value ) {
30 -
 30+ return strlen( trim( $value ) ) > 0;
3131 }
3232
3333 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/criteria/CriterionIsFloat.php
@@ -18,7 +18,7 @@
1919 *
2020 * @since 0.4
2121 */
22 - public function __construct( ) {
 22+ public function __construct() {
2323 parent::__construct();
2424 }
2525
@@ -26,7 +26,7 @@
2727 * @see ParameterCriterion::validate
2828 */
2929 public function validate( $value ) {
30 -
 30+ return preg_match( '/^\d+(\.\d+)?$/', $value );
3131 }
3232
3333 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/criteria/CriterionIsInteger.php
@@ -26,7 +26,7 @@
2727 * @see ParameterCriterion::validate
2828 */
2929 public function validate( $value ) {
30 -
 30+ return ctype_digit( (string)$value );
3131 }
3232
3333 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/ParameterCriterion.php
@@ -20,6 +20,8 @@
2121 * @param string $value
2222 *
2323 * @since 0.4
 24+ *
 25+ * @return boolean
2426 */
2527 public abstract function validate( $value );
2628

Status & tagging log