Passed
Push — develop ( e920eb...9cd2fd )
by BENARD
05:00
created

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