r72420 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72419‎ | r72420 | r72421 >
Date:13:09, 5 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Implemented CriterionInRange validation
Modified paths:
  • /trunk/extensions/Validator/includes/criteria/CriterionHasLength.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionInRange.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/criteria/CriterionHasLength.php
@@ -36,11 +36,7 @@
3737 */
3838 public function validate( $value ) {
3939 $strlen = strlen( $value );
40 -
41 - if ( $strlen > $this->upperBound ) return false;
42 - if ( $strlen < $this->lowerBound ) return false;
43 -
44 - return true;
 40+ return $strlen <= $this->upperBound && $strlen >= $this->lowerBound;
4541 }
4642
4743 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/criteria/CriterionInRange.php
@@ -13,20 +13,35 @@
1414 */
1515 class CriterionInRange extends ParameterCriterion {
1616
 17+ protected $lowerBound;
 18+ protected $upperBound;
 19+
1720 /**
1821 * Constructor.
1922 *
 23+ * @param integer $lowerBound
 24+ * @param integer $upperBound
 25+ *
2026 * @since 0.4
2127 */
22 - public function __construct( ) {
 28+ public function __construct( $lowerBound, $upperBound ) {
2329 parent::__construct();
 30+
 31+ $this->lowerBound = $lowerBound;
 32+ $this->upperBound = $upperBound;
2433 }
2534
2635 /**
2736 * @see ParameterCriterion::validate
2837 */
2938 public function validate( $value ) {
 39+ if ( ! is_numeric( $value ) ) {
 40+ return false;
 41+ }
3042
 43+ $value = (int)$value;
 44+
 45+ return $value <= $this->upperBound && $value >= $this->lowerBound;
3146 }
3247
3348 }
\ No newline at end of file

Status & tagging log