Conditions | 7 |
Paths | 10 |
Total Lines | 28 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
26 | public function doValidation( $value ) { |
||
27 | if ( !is_array( $value ) ) { |
||
28 | $this->addErrorMessage( 'Not an array' ); |
||
29 | return; |
||
30 | } |
||
31 | |||
32 | $validator = new RangeValidator(); |
||
33 | |||
34 | if ( array_key_exists( 'elementcount', $this->options ) ) { |
||
35 | $range = $this->options['elementcount']; |
||
36 | |||
37 | if ( !is_array( $range ) || count( $range ) !== 2 ) { |
||
38 | throw new Exception( 'The elementcount option must be an array with two elements' ); |
||
39 | } |
||
40 | |||
41 | $validator->setRange( $range[0], $range[1] ); |
||
42 | } |
||
43 | |||
44 | // min- and maxelements options are allowed to overwrite the elementcount option! |
||
45 | if ( array_key_exists( 'minelements', $this->options ) ) { |
||
46 | $validator->setLowerBound( $this->options['minelements'] ); |
||
47 | } |
||
48 | if ( array_key_exists( 'maxelements', $this->options ) ) { |
||
49 | $validator->setUpperBound( $this->options['maxelements'] ); |
||
50 | } |
||
51 | |||
52 | $this->runSubValidator( count( $value ), $validator, 'length' ); |
||
53 | } |
||
54 | |||
67 |