Conditions | 9 |
Paths | 33 |
Total Lines | 35 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | protected function validate($value, $key = null) |
||
17 | { |
||
18 | $executor = clone $this; |
||
19 | |||
20 | if (is_null($value) && $executor->optional) { |
||
|
|||
21 | if (is_null($executor->defaultValue)) { |
||
22 | return null; |
||
23 | } else { |
||
24 | $value = $this->defaultValue; |
||
25 | } |
||
26 | } |
||
27 | |||
28 | try { |
||
29 | reset($executor->validationStack); |
||
30 | |||
31 | do { |
||
32 | /** @var callable $validator */ |
||
33 | $validator = current($executor->validationStack); |
||
34 | $retVal = $validator($value, $key); |
||
35 | $value = $retVal === null ? $value : $retVal; |
||
36 | } while (next($executor->validationStack)); |
||
37 | |||
38 | if ($executor->toBool) { |
||
39 | return true; |
||
40 | } |
||
41 | |||
42 | return $value; |
||
43 | } catch (ValidationException $validationException) { |
||
44 | if ($executor->toBool) { |
||
45 | return false; |
||
46 | } |
||
47 | |||
48 | return ValidationError::fromException($validationException); |
||
49 | } |
||
50 | } |
||
51 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: