| Conditions | 4 |
| Paths | 4 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 41 | public function validate($property, Constraint $constraint) |
||
| 42 | { |
||
| 43 | if (!$constraint instanceof AllowedCommand) { |
||
| 44 | throw new UnexpectedTypeException($constraint, AllowedCommand::class); |
||
| 45 | } |
||
| 46 | |||
| 47 | $commandParts = explode(':', $property); |
||
| 48 | |||
| 49 | if (empty($commandParts) === false) { |
||
| 50 | if (in_array($commandParts[0], $this->allowedPrefixes)) { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->context->buildViolation($constraint->message) |
||
|
|
|||
| 56 | ->addViolation(); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |
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: