| 1 | <?php | ||
| 17 | class GreaterThan 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 | * Whether this rule supports certain validators | ||
| 40 | * | ||
| 41 | * @param ValidatorInterface $validator | ||
| 42 | * @return mixed | ||
| 43 | */ | ||
| 44 | public function canHandle(ValidatorInterface $validator) | ||
| 48 | } | ||
| 49 | 
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: