Failed Conditions
Push — develop ( afa323...bcac9d )
by Sam
04:23
created

DomainRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 2
eloc 12
c 0
b 0
f 0
dl 0
loc 19
ccs 11
cts 12
cp 0.9167
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getByCards() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\Card;
8
use Application\Model\Domain;
9
use Doctrine\ORM\QueryBuilder;
10
11
/**
12
 * @extends AbstractHasParentRepository<Domain>
13
 */
14
class DomainRepository extends AbstractHasParentRepository
15
{
16 1
    public function getByCards(QueryBuilder $cardQb): array
17
    {
18 1
        $cardIds = array_map(fn ($card) => $card->getId(), $cardQb->getQuery()->getResult());
0 ignored issues
show
Bug introduced by
It seems like $cardQb->getQuery()->getResult() can also be of type integer; however, parameter $array of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

18
        $cardIds = array_map(fn ($card) => $card->getId(), /** @scrutinizer ignore-type */ $cardQb->getQuery()->getResult());
Loading history...
19
20 1
        if (count($cardIds) === 0) {
21
            return [];
22
        }
23
24 1
        $qb = $this
25 1
            ->createQueryBuilder('d')
26 1
            ->innerJoin(Card::class, 'c')
27 1
            ->innerJoin('c.domains', 'd2', 'WITH', 'd2.id = d.id')
28 1
            ->where('c.id in (' . implode(',', $cardIds) . ')')
29 1
            ->groupBy('d.id')
30 1
            ->orderBy('COUNT(c.id)', 'DESC');
31
32 1
        return $qb->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $qb->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...
33
    }
34
}
35