These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\DashboardBundle\Repository; |
||
4 | |||
5 | use Doctrine\ORM\EntityRepository; |
||
6 | |||
7 | /** |
||
8 | * AnalyticsSegmentRepository |
||
9 | * |
||
10 | * This class was generated by the Doctrine ORM. Add your own custom |
||
11 | * repository methods below. |
||
12 | */ |
||
13 | class AnalyticsSegmentRepository extends EntityRepository |
||
14 | { |
||
15 | /** |
||
16 | * Get a segment |
||
17 | * |
||
18 | * @param int $id |
||
19 | * |
||
20 | * @return AnalyticsOverview|bool |
||
21 | */ |
||
22 | public function deleteSegment($id) |
||
23 | { |
||
24 | $em = $this->getEntityManager(); |
||
25 | $qb = $em->createQueryBuilder(); |
||
26 | $qb->select('s') |
||
27 | ->from('KunstmaanDashboardBundle:AnalyticsSegment', 's') |
||
28 | ->where('s.id = :id') |
||
29 | ->setParameter('id', $id); |
||
30 | |||
31 | $results = $qb->getQuery()->getResult(); |
||
32 | if ($results) { |
||
33 | $em->remove($results[0]); |
||
34 | $em->flush(); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Initialise a segment by adding new overviews if they don't exist yet |
||
40 | * |
||
41 | * @param AnalyticsSegment $segment |
||
42 | * @param int $configId |
||
43 | */ |
||
44 | public function initSegment($segment, $configId = false) |
||
45 | { |
||
46 | if (!\count($segment->getOverviews()->toArray())) { |
||
47 | if ($configId) { |
||
48 | $config = $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->find($configId); |
||
49 | } else { |
||
50 | $config = $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->findFirst(); |
||
51 | } |
||
52 | $this->getEntityManager()->getRepository('KunstmaanDashboardBundle:AnalyticsOverview')->addOverviews($config, $segment); |
||
0 ignored issues
–
show
|
|||
53 | } |
||
54 | } |
||
55 | } |
||
56 |
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: