| Conditions | 3 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | 21 | public function __invoke($subject, string $field): bool |
|
| 18 | { |
||
| 19 | 21 | $value = $subject->$field; |
|
| 20 | 21 | if ($this->isCanonical($value)) { |
|
| 21 | 3 | return true; |
|
| 22 | } |
||
| 23 | |||
| 24 | // force to hex only |
||
| 25 | 18 | $value = preg_replace('/[^a-f0-9]/i', '', $subject->$field); |
|
| 26 | 18 | if (!$this->isHexOnly($value)) { |
|
| 27 | // not hex-only, cannot sanitize |
||
| 28 | 6 | return false; |
|
| 29 | } |
||
| 30 | |||
| 31 | // add the dashes |
||
| 32 | 12 | $subject->$field = substr($value, 0, 8) . '-' |
|
| 33 | 12 | . substr($value, 8, 4) . '-' |
|
| 34 | 12 | . substr($value, 12, 4) . '-' |
|
| 35 | 12 | . substr($value, 16, 4) . '-' |
|
| 36 | 12 | . substr($value, 20); |
|
| 37 | |||
| 38 | 12 | return true; |
|
| 39 | } |
||
| 41 |