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