PlayerRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTop() 0 16 1
A __construct() 0 3 1
A getTotalNbPostDay() 0 11 1
A getTotalNbPlayer() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\DwhBundle\Repository;
6
7
use DateTime;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Doctrine\ORM\NonUniqueResultException;
10
use Doctrine\ORM\NoResultException;
11
use Doctrine\Persistence\ManagerRegistry;
12
use VideoGamesRecords\DwhBundle\Entity\Player;
13
14
class PlayerRepository extends ServiceEntityRepository
15
{
16
    public function __construct(ManagerRegistry $registry)
17
    {
18
        parent::__construct($registry, Player::class);
19
    }
20
21
    /**
22
     * @param DateTime $begin
23
     * @param DateTime $end
24
     * @param integer  $limit
25
     * @return array
26
     */
27
    public function getTop(DateTime $begin, DateTime $end, int $limit = 20): array
28
    {
29
        $query = $this->_em->createQuery("
30
            SELECT p.id,
31
                   SUM(p.nbPostDay) as nb      
32
            FROM VideoGamesRecords\DwhBundle\Entity\Player p
33
            WHERE p.date BETWEEN :begin AND :end
34
            GROUP BY p.id
35
            HAVING nb > 0
36
            ORDER BY nb DESC");
37
38
        $query->setParameter('begin', $begin);
39
        $query->setParameter('end', $end);
40
        $query->setMaxResults($limit);
41
42
        return $query->getArrayResult();
43
    }
44
45
    /**
46
     * @param DateTime $begin
47
     * @param DateTime $end
48
     * @return mixed
49
     * @throws NoResultException
50
     * @throws NonUniqueResultException
51
     */
52
    public function getTotalNbPlayer(DateTime $begin, DateTime $end): mixed
53
    {
54
        $query = $this->_em->createQuery("
55
            SELECT COUNT(DISTINCT(p.id)) as nb
56
            FROM VideoGamesRecords\DwhBundle\Entity\Player p
57
            WHERE p.date BETWEEN :begin AND :end
58
            AND p.nbPostDay > 0");
59
60
        $query->setParameter('begin', $begin);
61
        $query->setParameter('end', $end);
62
63
        return $query->getSingleScalarResult();
64
    }
65
66
    /**
67
     * @param DateTime $begin
68
     * @param DateTime $end
69
     * @return mixed
70
     * @throws NoResultException
71
     * @throws NonUniqueResultException
72
     */
73
    public function getTotalNbPostDay(DateTime $begin, DateTime $end): mixed
74
    {
75
        $query = $this->_em->createQuery("
76
            SELECT SUM(p.nbPostDay) as nb
77
            FROM VideoGamesRecords\DwhBundle\Entity\Player p
78
            WHERE p.date BETWEEN :begin AND :end");
79
80
        $query->setParameter('begin', $begin);
81
        $query->setParameter('end', $end);
82
83
        return $query->getSingleScalarResult();
84
    }
85
}
86