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

TeamChartRankingQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 25
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRankingMedals() 0 3 1
A getRankingPoints() 0 31 5
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
use VideoGamesRecords\CoreBundle\Contracts\Ranking\RankingQueryInterface;
8
9
class TeamChartRankingQuery extends AbstractRankingQuery implements RankingQueryInterface
10
{
11
    /**
12
     * @param int|null $id
13
     * @param array $options
14
     * @return array
15
     * @throws ORMException
16
     */
17
    public function getRankingPoints(int $id = null, array $options = []): array
18
    {
19
        $chart = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Chart')->find($id);
20
        if (null === $chart) {
21
            return [];
22
        }
23
24
        $maxRank = $options['maxRank'] ?? null;
25
        $team = $this->getTeam();
26
27
        $query = $this->em->createQueryBuilder()
28
            ->select('tc')
29
            ->from('VideoGamesRecords\CoreBundle\Entity\TeamChart', 'tc')
30
            ->join('tc.team', 't')
31
            ->addSelect('t')
32
            ->orderBy('tc.rankPointChart');
33
34
        $query->where('tc.chart = :chart')
35
            ->setParameter('chart', $chart);
36
37
        if (($maxRank !== null) && ($team !== null)) {
38
            $query->andWhere('(tc.rankPointChart <= :maxRank OR tc.team = :team)')
39
                ->setParameter('maxRank', $maxRank)
40
                ->setParameter('team', $team);
41
        } elseif ($maxRank !== null) {
42
            $query->andWhere('tc.rankPointChart <= :maxRank')
43
                ->setParameter('maxRank', $maxRank);
44
        } else {
45
            $query->setMaxResults(100);
46
        }
47
        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...
48
    }
49
50
    /**
51
     * @param int|null $id
52
     * @param array $options
53
     * @return array
54
     */
55
    public function getRankingMedals(int $id = null, array $options = []): array
56
    {
57
        return [];
58
    }
59
}
60