| Conditions | 5 |
| Paths | 4 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 5.5069 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | 3 | public function __invoke($subject, string $field): bool |
|
| 25 | { |
||
| 26 | 3 | $value = $subject->$field; |
|
| 27 | |||
| 28 | 3 | if (!is_scalar($value)) { |
|
| 29 | return false; |
||
| 30 | } |
||
| 31 | |||
| 32 | 3 | $value = preg_replace('/[^0-9a-f]/i', '', $value); |
|
| 33 | 3 | if ($value === '') { |
|
| 34 | return false; |
||
| 35 | } |
||
| 36 | |||
| 37 | 3 | if ($this->max && strlen($value) > $this->max) { |
|
|
|
|||
| 38 | $value = substr($value, 0, $this->max); |
||
| 39 | } |
||
| 40 | |||
| 41 | 3 | $subject->$field = $value; |
|
| 42 | |||
| 43 | 3 | return true; |
|
| 44 | } |
||
| 45 | } |
||
| 46 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: