r74219 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74218‎ | r74219 | r74220 >
Date:16:06, 3 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.4 - some fixes
Modified paths:
  • /trunk/extensions/Validator/includes/ItemParameterCriterion.php (modified) (history)
  • /trunk/extensions/Validator/includes/ItemParameterManipulation.php (modified) (history)
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/manipulations/ParamManipulationImplode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/manipulations/ParamManipulationImplode.php
@@ -49,7 +49,7 @@
5050 * @since 0.4
5151 */
5252 public function manipulate( Parameter &$parameter, array &$parameters ) {
53 - $parameter->value = $this->wrapper . implode( $this->wrapper . $this->delimiter . $this->wrapper, $parameter->value ) . $this->wrapper;
 53+ $parameter->setValue( $this->wrapper . implode( $this->wrapper . $this->delimiter . $this->wrapper, $parameter->getValue() ) . $this->wrapper );
5454 }
5555
5656 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/ItemParameterCriterion.php
@@ -79,15 +79,15 @@
8080 public function validate( Parameter $parameter ) {
8181 $result = new CriterionValidationResult();
8282
83 - if ( is_array( $parameter->value ) ) {
84 - foreach ( $parameter->value as $item ) {
 83+ if ( is_array( $parameter->getValue() ) ) {
 84+ foreach ( $parameter->getValue() as $item ) {
8585 if ( !$this->doValidation( $item ) ) {
8686 $result->addInvalidItem( $item );
8787 }
8888 }
8989
9090 if ( $result->hasInvalidItems() ) {
91 - $allInvalid = count( $result->getInvalidItems() ) == count( $parameter->value );
 91+ $allInvalid = count( $result->getInvalidItems() ) == count( $parameter->getValue() );
9292
9393 // If the parameter is required and all items are invalid, it's fatal.
9494 // Else it's high for required, and normal for non-required parameters.
@@ -107,7 +107,7 @@
108108 }
109109 }
110110 else {
111 - if ( !$this->doValidation( $parameter->value ) ) {
 111+ if ( !$this->doValidation( $parameter->getValue() ) ) {
112112 $result->addError(
113113 new ValidationError(
114114 $this->getItemErrorMessage( $parameter ),
Index: trunk/extensions/Validator/includes/ItemParameterManipulation.php
@@ -51,13 +51,14 @@
5252 * @since 0.4
5353 */
5454 public function manipulate( Parameter &$parameter, array &$parameters ) {
55 - if ( is_array( $parameter->value ) ) {
56 - foreach ( $parameter->value as &$item ) {
 55+ if ( is_array( $parameter->getValue() ) ) {
 56+ $value = &$parameter->getValue();
 57+ foreach ( $value as &$item ) {
5758 $this->doManipulation( $item, $parameters );
5859 }
5960 }
6061 else {
61 - $this->doManipulation( $parameter->value, $parameters );
 62+ $this->doManipulation( $parameter->getValue(), $parameters );
6263 }
6364 }
6465
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -55,7 +55,7 @@
5656 *
5757 * @var array
5858 */
59 - public $dependencies = array();
 59+ protected $dependencies = array();
6060
6161 /**
6262 * The default value for the parameter, or null when the parameter is required.
@@ -64,7 +64,7 @@
6565 *
6666 * @var mixed
6767 */
68 - public $default;
 68+ protected $default;
6969
7070 /**
7171 * The main name of the parameter.
@@ -134,13 +134,11 @@
135135 /**
136136 * The value of the parameter.
137137 *
138 - * TODO: protected
139 - *
140138 * @since 0.4
141139 *
142140 * @var mixed
143141 */
144 - public $value;
 142+ protected $value;
145143
146144 /**
147145 * Keeps track of how many times the parameter has been set by the user.
@@ -263,7 +261,7 @@
264262 }
265263
266264 if ( array_key_exists( 'dependencies', $definition ) ) {
267 - $parameter->dependencies = (array)$definition['dependencies'];
 265+ $parameter->addDependencies( $definition['dependencies'] );
268266 }
269267
270268 return $parameter;
@@ -335,6 +333,19 @@
336334 }
337335
338336 /**
 337+ * Adds one or more dependencies. There are the names of parameters
 338+ * that need to be validated and formatted before this one.
 339+ *
 340+ * @since 0.4
 341+ *
 342+ * @return array
 343+ */
 344+ public function addDependencies() {
 345+ $args = func_get_args();
 346+ $this->dependencies = array_merge( $this->dependencies, is_array( $args[0] ) ? $args[0] : $args );
 347+ }
 348+
 349+ /**
339350 * Adds one or more ParameterManipulation.
340351 *
341352 * @since 0.4
@@ -386,6 +397,17 @@
387398 }
388399
389400 /**
 401+ * Sets the value.
 402+ *
 403+ * @since 0.4
 404+ *
 405+ * @param mixed $value
 406+ */
 407+ public function setValue( $value ) {
 408+ $this->value = $value;
 409+ }
 410+
 411+ /**
390412 * Sets the $value to a cleaned value of $originalValue.
391413 *
392414 * @since 0.4
@@ -517,7 +539,7 @@
518540 */
519541 public function getDependencies() {
520542 return $this->dependencies;
521 - }
 543+ }
522544
523545 /**
524546 * Returns the original use-provided name.

Status & tagging log