1 | <?php |
||
11 | abstract class AbstractCronTimeFormatValidator extends ConstraintValidator |
||
12 | { |
||
13 | /** |
||
14 | * @param string|int $value |
||
15 | * @param Constraint $constraint |
||
16 | */ |
||
17 | public function validate($value, Constraint $constraint) |
||
31 | |||
32 | /** |
||
33 | * @param array $list |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | private function validateList($list) |
||
47 | |||
48 | /** |
||
49 | * @param int|string $item |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | private function validateItem($item) |
||
61 | |||
62 | /** |
||
63 | * @param int|string $range |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | private function validateRange($range) |
||
83 | |||
84 | /** |
||
85 | * @param int|string $item |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | abstract protected function validateTimeEntry($item); |
||
90 | } |
||
91 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: