Completed
Push — master ( d15cf4...5163a0 )
by Valentyn
06:05
created

MovieRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 16.66%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 30
ccs 3
cts 18
cp 0.1666
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A search() 0 11 1
A getTmdbIds() 0 10 1
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Movies\Repository;
5
6
use App\Movies\Entity\Movie;
7
use App\Movies\Entity\MovieTranslations;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Doctrine\Common\Collections\Criteria;
10
use Doctrine\Common\Collections\Expr\Expression;
11
use Doctrine\Common\Collections\ExpressionBuilder;
12
use Symfony\Bridge\Doctrine\RegistryInterface;
13
14
/**
15
 * @method Movie|null find($id, $lockMode = null, $lockVersion = null)
16
 * @method Movie|null findOneBy(array $criteria, array $orderBy = null)
17
 * @method Movie[]    findAll()
18
 * @method Movie[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
19
 */
20
class MovieRepository extends ServiceEntityRepository
21
{
22 1
    public function __construct(RegistryInterface $registry)
23
    {
24 1
        parent::__construct($registry, Movie::class);
25 1
    }
26
27
    public function search(string $query)
28
    {
29
        $query = mb_strtolower($query);
30
        $result = $this->createQueryBuilder('m')
31
            ->leftJoin('m.translations', 't')
32
            ->andWhere('LOWER(m.originalTitle) LIKE :title OR LOWER(t.title) LIKE :title')
33
            ->setParameter('title', "%{$query}%")
34
            ->getQuery()->getResult();
35
36
        return $result;
37
    }
38
39
    public function getTmdbIds(array $ids)
40
    {
41
        $result = $this->createQueryBuilder('m')
42
            ->select('m.tmdb.id')
43
            ->where('m.tmdb.id IN (:ids)')
44
            ->setParameter('ids', $ids)
45
            ->getQuery()->getArrayResult();
46
47
        return $result;
48
    }
49
}
50