| Conditions | 3 |
| Paths | 3 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 33 | 7 | public function __invoke($subject, $field) |
|
| 34 | { |
||
| 35 | 7 | $value = $subject->$field; |
|
| 36 | 7 | if ($this->isCanonical($value)) { |
|
| 37 | // already a canonical value |
||
| 38 | 1 | return true; |
|
| 39 | } |
||
| 40 | |||
| 41 | // force to hex only |
||
| 42 | 6 | $value = preg_replace('/[^a-f0-9]/i', '', $subject->$field); |
|
| 43 | 6 | if (! $this->isHexOnly($value)) { |
|
| 44 | // not hex-only, cannot sanitize |
||
| 45 | 2 | return false; |
|
| 46 | } |
||
| 47 | |||
| 48 | // add the dashes |
||
| 49 | 4 | $subject->$field = substr($value, 0, 8) . '-' |
|
| 50 | 4 | . substr($value, 8, 4) . '-' |
|
| 51 | 4 | . substr($value, 12, 4) . '-' |
|
| 52 | 4 | . substr($value, 16, 4) . '-' |
|
| 53 | 4 | . substr($value, 20); |
|
| 54 | |||
| 55 | // done! |
||
| 56 | 4 | return true; |
|
| 57 | } |
||
| 58 | } |
||
| 59 |