| Total Complexity | 5 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class ValidPattern implements Rule |
||
| 8 | { |
||
| 9 | public function __construct( |
||
| 10 | private int $length, |
||
| 11 | private string $separator = '-' |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Check text with specific pattern. |
||
| 16 | */ |
||
| 17 | public function passes($attribute, $value): bool |
||
| 18 | { |
||
| 19 | $texts = explode($this->separator, $value); |
||
| 20 | |||
| 21 | foreach ($texts as $text) { |
||
| 22 | if (strlen($text) !== $this->length) { |
||
| 23 | return false; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | return true; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get the validation error message. |
||
| 32 | */ |
||
| 33 | public function message(): string |
||
| 36 | } |
||
| 37 | } |
||
| 38 |