1 | <?php |
||
10 | class EnumRule implements Rule |
||
11 | { |
||
12 | /** @property string $enumClass */ |
||
13 | protected $enumClass; |
||
14 | |||
15 | /** |
||
16 | * @param string $enumClass Class of the enum to validate against |
||
17 | */ |
||
18 | 6 | public function __construct(string $enumClass) |
|
28 | |||
29 | /** |
||
30 | * Determine if the validation rule is an valid enum. |
||
31 | * |
||
32 | * @param string $attribute |
||
33 | * @param mixed $value |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | 4 | public function passes($attribute, $value): bool |
|
43 | |||
44 | /** |
||
45 | * Get the validation error message. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | 2 | public function message() |
|
53 | |||
54 | /** |
||
55 | * Validate that the given class is an Enum |
||
56 | * |
||
57 | * @param string $enumClass |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 6 | protected function isEnumClass(string $enumClass): bool |
|
66 | |||
67 | /** |
||
68 | * Pretty error message to indicate which class to implement |
||
69 | * |
||
70 | * @param string $enumClass |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 2 | protected function invalidEnumMessage(string $enumClass): string |
|
82 | } |
||
83 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.