Passed
Branch develop (21f7ca)
by BENARD
04:27
created

TeamProvider::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 22
nc 1
nop 0
dl 0
loc 25
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\DataProvider\Core;
4
5
use DateTime;
6
7
class TeamProvider extends AbstractTablePlayerProvider
8
{
9
    /**
10
     * @return array
11
     */
12
    public function getData(): array
13
    {
14
        $query = $this->em->createQuery(
15
            "
16
            SELECT t.id,
17
                   t.pointChart,
18
                   t.pointBadge,
19
                   t.chartRank0,
20
                   t.chartRank1,
21
                   t.chartRank2,
22
                   t.chartRank3,
23
                   t.rankPointChart,
24
                   t.rankMedal,
25
                   t.rankBadge,
26
                   t.rankCup,
27
                   t.gameRank0,
28
                   t.gameRank1,
29
                   t.gameRank2,
30
                   t.gameRank3,
31
                   t.nbMasterBadge,
32
                   t.pointGame,
33
                   t.rankPointGame                  
34
            FROM VideoGamesRecords\CoreBundle\Entity\Team t"
35
        );
36
        return $query->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
39
    /**
40
     * @param DateTime $date1
41
     * @param DateTime $date2
42
     * @return array
43
     */
44
    public function getNbPostDay(DateTime $date1, DateTime $date2): array
45
    {
46
        $query = $this->em->createQuery(
47
            "
48
            SELECT
49
                 t.id,
50
                 COUNT(pc.id) as nb
51
            FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
52
            JOIN pc.player p
53
            JOIN p.team t
54
            WHERE pc.lastUpdate BETWEEN :date1 AND :date2
55
            GROUP BY t.id"
56
        );
57
58
        $query->setParameter('date1', $date1);
59
        $query->setParameter('date2', $date2);
60
        $result = $query->getResult();
61
62
        $data = array();
63
        foreach ($result as $row) {
64
            $data[$row['id']] = $row['nb'];
65
        }
66
        return $data;
67
    }
68
}
69
70