Conditions | 3 |
Paths | 4 |
Total Lines | 12 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
38 | public function getMessages(ValidatorInterface $validator) |
||
39 | { |
||
40 | $messages = []; |
||
41 | if ($validator->getMin() > 0) { |
||
42 | $messages['minlength'] = sprintf($this->translateMessage('At least %s characters are required'), $validator->getMin()); |
||
43 | } |
||
44 | if ($validator->getMax() > 0) { |
||
45 | $messages['maxlength'] = sprintf($this->translateMessage('At most %s characters are allowed'), $validator->getMax()); |
||
46 | } |
||
47 | |||
48 | return $messages; |
||
49 | } |
||
50 | |||
62 |
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: