Conditions | 9 |
Paths | 33 |
Total Lines | 33 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | protected function validate($value, $key = null) |
||
17 | { |
||
18 | if (is_null($value) && $this->optional) { |
||
|
|||
19 | if (is_null($this->defaultValue)) { |
||
20 | return null; |
||
21 | } else { |
||
22 | $value = $this->defaultValue; |
||
23 | } |
||
24 | } |
||
25 | |||
26 | try { |
||
27 | reset($this->validationStack); |
||
28 | |||
29 | do { |
||
30 | /** @var callable $validator */ |
||
31 | $validator = current($this->validationStack); |
||
32 | $retVal = $validator($value, $key); |
||
33 | $value = $retVal === null ? $value : $retVal; |
||
34 | } while (next($this->validationStack)); |
||
35 | |||
36 | if ($this->toBool) { |
||
37 | return true; |
||
38 | } |
||
39 | |||
40 | return $value; |
||
41 | } catch (ValidationException $validationException) { |
||
42 | if ($this->toBool) { |
||
43 | return false; |
||
44 | } |
||
45 | |||
46 | return ValidationError::fromException($validationException); |
||
47 | } |
||
48 | } |
||
49 | } |
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: