Completed
Push — master ( bb4d5a...e8c3b1 )
by Valentyn
04:47
created

MovieActorRepository::findAllByMovie()   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 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Movies\Repository;
6
7
use App\Movies\Entity\MovieActor;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Doctrine\ORM\Query;
10
use Symfony\Bridge\Doctrine\RegistryInterface;
11
12
/**
13
 * @method MovieActor|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method MovieActor|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method MovieActor[]    findAll()
16
 * @method MovieActor[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class MovieActorRepository extends ServiceEntityRepository
19
{
20 1
    public function __construct(RegistryInterface $registry)
21
    {
22 1
        parent::__construct($registry, MovieActor::class);
23 1
    }
24
25 1
    public function findAllByMovie(int $movieId): Query
26
    {
27 1
        return $this->createQueryBuilder('ma')
28 1
            ->leftJoin('ma.actor', 'a')
29 1
            ->addSelect('a')
30 1
            ->where('ma.movie = :movieId')
31 1
            ->setParameter('movieId', $movieId)
32 1
            ->getQuery();
33
    }
34
35
    public function findAllByActor(int $actorId): Query
36
    {
37
        return $this->createQueryBuilder('ma')
38
            ->leftJoin('ma.movie', 'm')
39
            ->addSelect('m')
40
            ->where('ma.actor = :actorId')
41
            ->setParameter('actorId', $actorId)
42
            ->getQuery();
43
    }
44
}
45