Completed
Push — master ( 5163a0...712d21 )
by Valentyn
06:59
created

SearchService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A findByQuery() 0 13 2
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Movies\Service;
5
6
use App\Movies\Entity\Movie;
7
use App\Movies\Repository\MovieRepository;
8
9
class SearchService
10
{
11
    private $repository;
12
    private $tmdb;
13
    private $sync;
14
    private $normalizer;
15
16 2
    public function __construct(MovieRepository $repository, TmdbSearchService $tmdb, TmdbSyncService $sync, TmdbNormalizerService $normalizer)
17
    {
18 2
        $this->repository = $repository;
19 2
        $this->tmdb = $tmdb;
20 2
        $this->sync = $sync;
21 2
        $this->normalizer = $normalizer;
22 2
    }
23
24
    /**
25
     * @param string $query
26
     * @param string $locale
27
     * @return Movie[]
28
     * @throws \Exception
29
     */
30 2
    public function findByQuery(string $query, string $locale): array
31
    {
32 2
        $movies = $this->repository->findByTitle($query);
33 2
        if (reset($movies)) {
34 1
            return $movies;
35
        }
36
37 1
        $movies = $this->tmdb->findMoviesByQuery($query, $locale);
38 1
        $movies = $this->normalizer->normalizeMoviesToObjects($movies['results'], $locale);
39 1
        $this->sync->syncMovies($movies);
40
41 1
        return $movies;
42
    }
43
}