| Conditions | 4 |
| Paths | 4 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function apply($builder, CriterionInterface $group): \Generator |
||
| 28 | { |
||
| 29 | $inner = $group->getQuery(); |
||
|
|
|||
| 30 | $expr = $builder->expr()->andX(); |
||
| 31 | |||
| 32 | foreach ($inner->getCriteria() as $where) { |
||
| 33 | $expression = parent::getDoctrineExpression($where, $builder->expr(), $where->getField()); |
||
| 34 | |||
| 35 | yield from $this->extractResult($expression, function ($current) use ($expr, $where, $builder) { |
||
| 36 | if ($where->isAnd()) { |
||
| 37 | $expr->add($current); |
||
| 38 | } else { |
||
| 39 | $builder->orWhere($current); |
||
| 40 | } |
||
| 41 | }); |
||
| 42 | } |
||
| 43 | |||
| 44 | $group->isAnd() |
||
| 45 | ? $builder->andWhere($expr) |
||
| 46 | : $builder->orWhere($expr); |
||
| 47 | } |
||
| 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: