| Conditions | 2 |
| Paths | 2 |
| Total Lines | 12 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| 1 | <?php |
||
| 38 | public function updateEntities($class, array $data, array $ids) |
||
| 39 | { |
||
| 40 | $qb = $this->doctrine->getManager()->createQueryBuilder() |
||
|
|
|||
| 41 | ->update($class, 'o') |
||
| 42 | ->where('o.id IN (:ids)') |
||
| 43 | ->setParameter('ids', $ids); |
||
| 44 | foreach ($data as $key => $value) { |
||
| 45 | $qb->set("o.$key", ":$key")->setParameter(":$key", $value); |
||
| 46 | } |
||
| 47 | |||
| 48 | $qb->getQuery()->execute(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
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: