Passed
Push — develop ( 462fa0...bd18e2 )
by BENARD
04:27
created

TeamRankingQuery::getRankingPointChart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\DataProvider\Ranking\Team;
4
5
use Doctrine\ORM\Exception\ORMException;
6
use VideoGamesRecords\CoreBundle\DataProvider\Ranking\AbstractRankingQuery;
7
8
class TeamRankingQuery extends AbstractRankingQuery
9
{
10
    /**
11
     * @param array $options
12
     * @return array
13
     * @throws ORMException
14
     */
15
    public function getRankingPointChart(array $options = []): array
16
    {
17
        return $this->getRanking('rankPointChart', $options);
18
    }
19
20
    /**
21
     * @param array $options
22
     * @return array
23
     * @throws ORMException
24
     */
25
    public function getRankingPointGame(array $options = []): array
26
    {
27
        return $this->getRanking('rankPointGame', $options);
28
    }
29
30
31
    /**
32
     * @param array $options
33
     * @return array
34
     * @throws ORMException
35
     */
36
    public function getRankingMedals(array $options = []): array
37
    {
38
        return $this->getRanking('rankMedal', $options);
39
    }
40
41
    /**
42
     * @param array $options
43
     * @return array
44
     * @throws ORMException
45
     */
46
    public function getRankingBadge(array $options = []): array
47
    {
48
        return $this->getRanking('rankBadge', $options);
49
    }
50
51
    /**
52
     * @param array $options
53
     * @return array
54
     * @throws ORMException
55
     */
56
    public function getRankingCup(array $options = []): array
57
    {
58
        return $this->getRanking('rankCup', $options);
59
    }
60
61
62
    /**
63
     * @param string $column
64
     * @param array  $options
65
     * @return array
66
     * @throws ORMException
67
     */
68
    private function getRanking(string $column = 'rankPointChart', array $options = []): array
69
    {
70
        $maxRank = $options['maxRank'] ?? 100;
71
        $team = $this->getTeam();
72
73
        $query = $this->em->createQueryBuilder()
74
            ->select('t')
75
            ->from('VideoGamesRecords\CoreBundle\Entity\Team', 't')
76
            ->where("t.$column IS NOT NULL")
77
            ->orderBy("t.$column");
78
79
        if ($team !== null) {
80
            $query->andWhere("(t.$column <= :maxRank OR t = :team)")
81
                ->setParameter('maxRank', $maxRank)
82
                ->setParameter('team', $team);
83
        } else {
84
            $query->andWhere("t.$column <= :maxRank")
85
                ->setParameter('maxRank', $maxRank);
86
        }
87
        return $query->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getQuery()->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...
88
    }
89
}
90