Completed
Push — master ( 71eba9...1e1a94 )
by Valentyn
04:31
created

MovieReviewRepository::findOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 8
cts 8
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Movies\Repository;
4
5
use App\Movies\Entity\MovieReview;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
use Doctrine\ORM\Query;
8
use Symfony\Bridge\Doctrine\RegistryInterface;
9
use App\Users\Entity\UserWatchedMovie;
10
11
/**
12
 * @method MovieReview|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method MovieReview|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method MovieReview[]    findAll()
15
 * @method MovieReview[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
16
 */
17
class MovieReviewRepository extends ServiceEntityRepository
18
{
19 1
    public function __construct(RegistryInterface $registry)
20
    {
21 1
        parent::__construct($registry, MovieReview::class);
22 1
    }
23
24
    /**
25
     * use this method instead of find(), because doctrine dont know how to map uwm correctly
26
     */
27 1
    public function findOne(int $id): ?MovieReview
28
    {
29 1
        return $this->createQueryBuilder('review')
30 1
            ->leftJoin('review.userWatchedMovie', 'uwm')
31 1
            ->addSelect('uwm')
32 1
            ->where('review.id = :id')
33 1
            ->setParameter('id', $id)
34 1
            ->getQuery()
35 1
            ->getOneOrNullResult();
36
    }
37
38 1
    public function findAllByMovie(string $locale, int $movieId): Query
39
    {
40 1
        return $this->createQueryBuilder('review')
41 1
            ->leftJoin('review.userWatchedMovie', 'uwm')
42 1
            ->addSelect('uwm')
43 1
            ->where('review.movie = :movieId AND review.locale = :locale')
44 1
            ->setParameter('movieId', $movieId)
45 1
            ->setParameter('locale', $locale)
46 1
            ->getQuery();
47
    }
48
}
49