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

PerformanceRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
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