Conditions | 2 |
Paths | 2 |
Total Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
27 | public function apply($builder, CriterionInterface $having): ?iterable |
||
28 | { |
||
29 | $expression = new Expression($builder, $having->getOperator(), $having->getValue()); |
||
30 | yield from $result = $expression->create($having->getField()); |
||
31 | |||
32 | if ($having->isAnd()) { |
||
33 | $builder->andHaving($result->getReturn()); |
||
34 | } else { |
||
35 | $builder->orHaving($result->getReturn()); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 |
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: