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

PlayerGameRankingQuery::getRankingPoints()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 35
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 35
rs 8.5546
c 0
b 0
f 0
cc 7
nc 9
nop 2
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\DataProvider\Ranking\Player;
4
5
use Doctrine\ORM\Exception\ORMException;
6
use VideoGamesRecords\CoreBundle\DataProvider\Ranking\AbstractRankingQuery;
7
use VideoGamesRecords\CoreBundle\Interface\Ranking\RankingQueryInterface;
0 ignored issues
show
Bug introduced by
The type VideoGamesRecords\CoreBu...g\RankingQueryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class PlayerGameRankingQuery 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
        $game = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game')->find($id);
20
        if (null === $game) {
21
            return [];
22
        }
23
24
        $maxRank = $options['maxRank'] ?? null;
25
        $player = $this->getPlayer();
26
        $team = !empty($options['idTeam']) ? $this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Team', $options['idTeam']) : null;
27
28
        $query = $this->em->createQueryBuilder()
29
            ->select('pg')
30
            ->from('VideoGamesRecords\CoreBundle\Entity\PlayerGame', 'pg')
31
            ->join('pg.player', 'p')
32
            ->addSelect('p')
33
            ->orderBy('pg.rankPointChart');
34
35
        $query->where('pg.game = :game')
36
            ->setParameter('game', $game);
37
38
        if ($team != null) {
39
            $query->andWhere('(p.team = :team)')
40
                ->setParameter('team', $team);
41
        } elseif (($maxRank !== null) && ($player !== null)) {
42
            $query->andWhere('(pg.rankPointChart <= :maxRank OR pg.player = :player)')
43
                ->setParameter('maxRank', $maxRank)
44
                ->setParameter('player', $player);
45
        } elseif ($maxRank !== null) {
46
            $query->andWhere('pg.rankPointChart <= :maxRank')
47
                ->setParameter('maxRank', $maxRank);
48
        } else {
49
            $query->setMaxResults(100);
50
        }
51
        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...
52
    }
53
54
    /**
55
     * @param int|null $id
56
     * @param array $options
57
     * @return array
58
     * @throws ORMException
59
     */
60
    public function getRankingMedals(int $id = null, array $options = []): array
61
    {
62
        $game = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Game')->find($id);
63
        if (null === $game) {
64
            return [];
65
        }
66
67
        $maxRank = $options['maxRank'] ?? null;
68
        $player = $this->getPlayer();
69
70
        $query = $this->em->createQueryBuilder()
71
            ->select('pg')
72
            ->from('VideoGamesRecords\CoreBundle\Entity\PlayerGame', 'pg')
73
            ->join('pg.player', 'p')
74
            ->addSelect('p')
75
            ->orderBy('pg.rankMedal');
76
77
        $query->where('pg.game = :game')
78
            ->setParameter('game', $game);
79
80
        if (($maxRank !== null) && ($player !== null)) {
81
            $query->andWhere('(pg.rankMedal <= :maxRank OR pg.player = :player)')
82
                ->setParameter('maxRank', $maxRank)
83
                ->setParameter('player', $player);
84
        } elseif ($maxRank !== null) {
85
            $query->andWhere('pg.rankMedal <= :maxRank')
86
                ->setParameter('maxRank', $maxRank);
87
        } else {
88
            $query->setMaxResults(100);
89
        }
90
91
        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...
92
    }
93
}
94