Completed
Pull Request — master (#191)
by Serhii
02:32
created

PerformanceRepository::findAllWithinSeasons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Performance;
6
use App\Entity\RepertoireSeason;
7
use Doctrine\Common\Persistence\ManagerRegistry;
8
9
class PerformanceRepository extends AbstractRepository
10 18
{
11
    public function __construct(ManagerRegistry $registry)
12 18
    {
13 18
        parent::__construct($registry, Performance::class);
14
    }
15
16
    /**
17
     * @return array|Performance[]
18 1
     */
19
    public function findAllWithinSeasons()
20 1
    {
21 1
        return $this->createQueryBuilder('p')
22 1
            ->innerJoin('p.seasons', 'ps')
23 1
            ->groupBy('p.id')
24 1
            ->orderBy('p.premiere', 'DESC')
25 1
            ->getQuery()
26
            ->enableResultCache(self::CACHE_TTL)
27
            ->execute();
28
    }
29
30
    /**
31
     * @return array|Performance[]
32
     */
33
    public function findAllWithinSeasonsExcept(RepertoireSeason $season): array
34
    {
35
        $ids = $season->getPerformances()
36
            ->map(fn (Performance $performance) => $performance->getId())
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_VARIABLE, expecting ',' or ')'
Loading history...
37
            ->toArray();
38
39
        $qb = $this->createQueryBuilder('p');
40
41
        $qb->innerJoin('p.seasons', 'ps')
42
            ->groupBy('p.id')
43
            ->orderBy('p.premiere', 'DESC');
44
45
        if (!empty($ids)) {
46
            $qb->where($qb->expr()->notIn('p.id', $ids));
47
        }
48
49
        return $qb
50
            ->getQuery()
51
            ->enableResultCache(self::CACHE_TTL)
52
            ->getResult()
53
        ;
54
    }
55
}
56