Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Repository/AnalyticsSegmentRepository.php (2 issues)

Upgrade to new PHP Analysis Engine

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
0 ignored issues
show
Should the return type not be AnalyticsOverview|boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
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
0 ignored issues
show
Should the type for parameter $configId not be false|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
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);
53
        }
54
    }
55
}
56