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

PlayerProvider::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 19
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\DataProvider\Core;
4
5
use DateTime;
6
7
class PlayerProvider extends AbstractTablePlayerProvider
8
{
9
    /**
10
     * @return array
11
     */
12
    public function getData(): array
13
    {
14
        $query = $this->em->createQuery(
15
            "
16
            SELECT p.id,
17
                   p.chartRank0,
18
                   p.chartRank1,
19
                   p.chartRank2,
20
                   p.chartRank3,
21
                   p.pointChart,
22
                   p.rankPointChart,
23
                   p.rankMedal,
24
                   p.nbChart,
25
                   p.pointGame,
26
                   p.rankPointGame                   
27
            FROM VideoGamesRecords\CoreBundle\Entity\Player p
28
            WHERE p.id <> 0"
29
        );
30
        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...
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function getDataRank(): array
37
    {
38
        $query = $this->em->createQuery("
39
                    SELECT
40
                         p.id,
41
                         CASE WHEN pc.rank > 29 THEN 30 ELSE pc.rank END AS rank,
42
                         COUNT(pc.id) as nb
43
                    FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
44
                    JOIN pc.player p
45
                    WHERE pc.rank > 3            
46
                    GROUP BY p.id, rank");
47
48
        $result = $query->getResult();
49
        $data = array();
50
        foreach ($result as $row) {
51
            $data[$row['id']][$row['rank']] = $row['nb'];
52
        }
53
        return $data;
54
    }
55
56
    /**
57
     * @param DateTime $date1
58
     * @param DateTime $date2
59
     * @return array
60
     */
61
    public function getNbPostDay(DateTime $date1, DateTime $date2): array
62
    {
63
        $query = $this->em->createQuery("
64
            SELECT
65
                 p.id,
66
                 COUNT(pc.chart) as nb
67
            FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
68
            JOIN pc.player p
69
            WHERE pc.lastUpdate BETWEEN :date1 AND :date2
70
            GROUP BY p.id");
71
72
73
        $query->setParameter('date1', $date1);
74
        $query->setParameter('date2', $date2);
75
        $result = $query->getResult();
76
77
        $data = array();
78
        foreach ($result as $row) {
79
            $data[$row['id']] = $row['nb'];
80
        }
81
        return $data;
82
    }
83
}
84
85