| Total Complexity | 3 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class ValidClassificationRule implements Rule |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Validation for Classification |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | const PATTERN = '^(.+)-([0-9]+)$'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Determine if the validation rule passes. |
||
| 20 | * |
||
| 21 | * @param string $attribute |
||
| 22 | * @param mixed $value |
||
| 23 | * @return boolean |
||
| 24 | */ |
||
| 25 | public function passes($attribute, $value) |
||
| 26 | { |
||
| 27 | $passesRegex = preg_match('/' . self::PATTERN . '/', $value, $matches); |
||
| 28 | if (!$passesRegex) { |
||
| 29 | return false; |
||
| 30 | } |
||
| 31 | $classificationCode = strToUpper($matches[1]); |
||
| 32 | return Classification::where('key', $classificationCode)->exists(); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Get the validation error message. |
||
| 37 | * |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | public function message() |
||
| 43 | } |
||
| 44 | } |
||
| 45 |