1 | <?php |
||
15 | class TmdbSearchService |
||
16 | { |
||
17 | private $apiKey; |
||
18 | private $client; |
||
19 | private $logger; |
||
20 | private $cache; |
||
21 | private const ApiUrl = 'https://api.themoviedb.org/3'; |
||
22 | |||
23 | 9 | public function __construct(LoggerInterface $logger, ClientInterface $client, CacheInterface $cache) |
|
30 | |||
31 | /** |
||
32 | * @param string $query |
||
33 | * @param string $locale |
||
34 | * @param array $data |
||
35 | * |
||
36 | * @throws TmdbMovieNotFoundException |
||
37 | * @throws TmdbRequestLimitException |
||
38 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | 1 | public function findMoviesByQuery(string $query, string $locale = 'en', $data = []): array |
|
56 | |||
57 | /** |
||
58 | * @param int $tmdb_id |
||
59 | * @param string $locale |
||
60 | * |
||
61 | * @throws TmdbMovieNotFoundException |
||
62 | * @throws TmdbRequestLimitException |
||
63 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | 1 | public function findMovieById(int $tmdb_id, string $locale = 'en'): array |
|
91 | |||
92 | /** |
||
93 | * @param int $movieId |
||
94 | * @param string $locale |
||
95 | * |
||
96 | * @throws TmdbMovieNotFoundException |
||
97 | * @throws TmdbRequestLimitException |
||
98 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | public function findActorsByMovieId(int $movieId, string $locale = 'en'): array |
||
113 | |||
114 | /** |
||
115 | * @param int $personId |
||
116 | * @param string $locale |
||
117 | * |
||
118 | * @throws TmdbMovieNotFoundException |
||
119 | * @throws TmdbRequestLimitException |
||
120 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | public function findActorById(int $personId, string $locale = 'en'): array |
||
140 | |||
141 | /** |
||
142 | * @param int $personId |
||
143 | * @param string $locale |
||
144 | * |
||
145 | * @throws TmdbMovieNotFoundException |
||
146 | * @throws TmdbRequestLimitException |
||
147 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | public function findActorTranslationsById(int $personId, string $locale = 'en'): array |
||
164 | |||
165 | /** |
||
166 | * @param int $tmdb_id |
||
167 | * |
||
168 | * @throws TmdbMovieNotFoundException |
||
169 | * @throws TmdbRequestLimitException |
||
170 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
171 | * |
||
172 | * @return array |
||
173 | */ |
||
174 | public function findMovieTranslationsById(int $tmdb_id): array |
||
184 | |||
185 | /** |
||
186 | * @param int $tmdb_id |
||
187 | * @param int $page |
||
188 | * |
||
189 | * @throws TmdbMovieNotFoundException |
||
190 | * @throws TmdbRequestLimitException |
||
191 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | public function findSimilarMoviesById(int $tmdb_id, int $page = 1): array |
||
206 | |||
207 | /** |
||
208 | * @param string $url |
||
209 | * @param string $method |
||
210 | * @param array $params |
||
211 | * |
||
212 | * @throws TmdbMovieNotFoundException |
||
213 | * @throws TmdbRequestLimitException |
||
214 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
215 | * |
||
216 | * @return array |
||
217 | */ |
||
218 | 2 | private function request(string $url, string $method = 'GET', array $params = []): array |
|
259 | |||
260 | 2 | private function arrayAsString(array $array): string |
|
273 | |||
274 | 2 | private function getCacheKeyFromParams(string $url, string $method = 'GET', array $params = []): string |
|
280 | |||
281 | /** |
||
282 | * @param string $url |
||
283 | * @param string $method |
||
284 | * @param array $params |
||
285 | * |
||
286 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
287 | * |
||
288 | * @return array|null |
||
289 | */ |
||
290 | 2 | private function getResponseFromCache(string $url, string $method = 'GET', array $params = []): ?array |
|
298 | } |
||
299 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.