1 | <?php |
||
17 | class Between extends AbstractRule |
||
18 | { |
||
19 | /** |
||
20 | * {@inheritDoc} |
||
21 | */ |
||
22 | public function getRules(ValidatorInterface $validator, ElementInterface $element = null) |
||
26 | |||
27 | /** |
||
28 | * {@inheritDoc} |
||
29 | */ |
||
30 | public function getMessages(ValidatorInterface $validator) |
||
37 | |||
38 | /** |
||
39 | * @param ValidatorInterface $validator |
||
40 | * |
||
41 | * @return mixed |
||
42 | */ |
||
43 | protected function getMin(ValidatorInterface $validator) |
||
47 | |||
48 | /** |
||
49 | * @param ValidatorInterface $validator |
||
50 | * |
||
51 | * @return mixed |
||
52 | */ |
||
53 | protected function getMax(ValidatorInterface $validator) |
||
57 | |||
58 | /** |
||
59 | * Whether this rule supports certain validators |
||
60 | * |
||
61 | * @param ValidatorInterface $validator |
||
62 | * @return mixed |
||
63 | */ |
||
64 | public function canHandle(ValidatorInterface $validator) |
||
68 | } |
||
69 |
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: