| Conditions | 3 |
| Paths | 2 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function mustBeBoolean($value, string $propertyPath = null, UIValidatorInterface $parentValidator = null, string $exceptionMessage = null): bool |
||
| 20 | { |
||
| 21 | 1 | $this->validationEngine->validateFieldValue( |
|
|
|
|||
| 22 | 1 | $parentValidator ?: $this, |
|
| 23 | 1 | function() use ($value, $propertyPath, $exceptionMessage) { |
|
| 24 | 1 | Assertion::inArray( |
|
| 25 | $value, |
||
| 26 | 1 | [true, false, 1, 0, '1', '0', 'true', 'false'], |
|
| 27 | $exceptionMessage, |
||
| 28 | $propertyPath |
||
| 29 | ); |
||
| 30 | 1 | } |
|
| 31 | ); |
||
| 32 | |||
| 33 | // Otherwise "false" would return true |
||
| 34 | 1 | if (in_array($value, [true, 'true', '1', 1], true)) { |
|
| 35 | 1 | return true; |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | return false; |
|
| 39 | } |
||
| 40 | } |
||
| 41 |
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: