| Conditions | 3 |
| Paths | 3 |
| Total Lines | 18 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 38 | public function check($value): bool |
||
| 39 | { |
||
| 40 | 2 | $this->requireParameters(['algo']); |
|
| 41 | |||
| 42 | 2 | $algo = strtoupper($this->parameter('algo')); |
|
| 43 | |||
| 44 | if (! isset($this->algorithmsLengths[$algo])) { |
||
| 45 | 2 | $algos = array_keys($this->algorithmsLengths); |
|
| 46 | |||
| 47 | 2 | throw new InvalidArgumentException('algo parameter must be one of ' . implode('/', $algos)); |
|
| 48 | } |
||
| 49 | |||
| 50 | 2 | $this->setParameterText('algorithm', $algo); |
|
| 51 | |||
| 52 | 2 | $length = $this->algorithmsLengths[$algo]; |
|
| 53 | 2 | $caseSensitive = (bool) ($this->parameter('allowUppercase', false)) ? 'i' : ''; |
|
| 54 | |||
| 55 | 2 | return preg_match(sprintf('/^[0-9a-f]{%s}$/%s', $length, $caseSensitive), $value) === 1; |
|
| 56 | } |
||
| 58 |