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

PlayerCountryRankingQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 18
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRankingMedals() 0 3 1
A getRankingPoints() 0 24 3
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\DataProvider\Ranking\Player;
4
5
use VideoGamesRecords\CoreBundle\DataProvider\Ranking\AbstractRankingQuery;
6
use VideoGamesRecords\CoreBundle\Contracts\Ranking\RankingQueryInterface;
7
8
class PlayerCountryRankingQuery extends AbstractRankingQuery implements RankingQueryInterface
9
{
10
    /**
11
     * @param int|null $id
12
     * @param array    $options
13
     * @return array
14
     */
15
    public function getRankingPoints(int $id = null, array $options = []): array
16
    {
17
        $country = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Country')->find($id);
18
        if (null === $country) {
19
            return [];
20
        }
21
22
        $maxRank = $options['maxRank'] ?? null;
23
24
        $query = $this->em->createQueryBuilder('p')
0 ignored issues
show
Unused Code introduced by
The call to Doctrine\ORM\EntityManag...e::createQueryBuilder() has too many arguments starting with 'p'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $query = $this->em->/** @scrutinizer ignore-call */ createQueryBuilder('p')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
            ->select('p')
26
            ->from('VideoGamesRecords\CoreBundle\Entity\Player', 'p')
27
            ->where('(p.country = :country)')
28
            ->setParameter('country', $country)
29
            ->orderBy('p.rankCountry');
30
31
        if ($maxRank !== null) {
32
            $query->andWhere('p.rankCountry <= :maxRank')
33
                ->setParameter('maxRank', $maxRank);
34
        } else {
35
            $query->setMaxResults($maxRank);
36
        }
37
38
        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...
39
    }
40
41
    /**
42
     * @param int|null $id
43
     * @param array $options
44
     * @return array
45
     */
46
    public function getRankingMedals(int $id = null, array $options = []): array
47
    {
48
        return array();
49
    }
50
}
51