Passed
Branch develop (4ef38d)
by BENARD
03:50
created

CoreTeamStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 24
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A getData() 0 26 1
A getNbPostDay() 0 23 2
1
<?php
2
3
namespace VideoGamesRecords\DwhBundle\DataProvider\Strategy\Core;
4
5
use DateTime;
6
use VideoGamesRecords\DwhBundle\Contracts\Strategy\CoreStrategyInterface;
7
8
class CoreTeamStrategy extends AbstractCoreProvider implements CoreStrategyInterface
9
{
10
    public function supports(string $name): bool
11
    {
12
        return $name === self::TYPE_TEAM;
13
    }
14
15
    /**
16
     * @return array
17
     */
18
    public function getData(): array
19
    {
20
        $conn = $this->em->getConnection();
21
        $sql = "SELECT t.id,
22
                   t.pointChart,
23
                   t.pointBadge,
24
                   t.chartRank0,
25
                   t.chartRank1,
26
                   t.chartRank2,
27
                   t.chartRank3,
28
                   t.rankPointChart,
29
                   t.rankMedal,
30
                   t.rankBadge,
31
                   t.rankCup,
32
                   t.gameRank0,
33
                   t.gameRank1,
34
                   t.gameRank2,
35
                   t.gameRank3,
36
                   t.nbMasterBadge,
37
                   t.pointGame,
38
                   t.rankPointGame                  
39
            FROM vgr_team t";
40
41
        $stmt = $conn->prepare($sql);
42
        $resultSet = $stmt->executeQuery();
43
        return $resultSet->fetchAllAssociative();
44
    }
45
46
    /**
47
     * @param DateTime $date1
48
     * @param DateTime $date2
49
     * @return array
50
     */
51
    public function getNbPostDay(DateTime $date1, DateTime $date2): array
52
    {
53
        $query = $this->em->createQuery(
54
            "
55
            SELECT
56
                 t.id,
57
                 COUNT(pc.id) as nb
58
            FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc
59
            JOIN pc.player p
60
            JOIN p.team t
61
            WHERE pc.lastUpdate BETWEEN :date1 AND :date2
62
            GROUP BY t.id"
63
        );
64
65
        $query->setParameter('date1', $date1);
66
        $query->setParameter('date2', $date2);
67
        $result = $query->getResult();
68
69
        $data = array();
70
        foreach ($result as $row) {
71
            $data[$row['id']] = $row['nb'];
72
        }
73
        return $data;
74
    }
75
}
76
77