@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function getMovies() : \Generator |
36 | 36 | { |
37 | - $response = $this->tmdb->getRequest('account/'.$this->account_id.'/rated/movies', $this->options); |
|
37 | + $response = $this->tmdb->getRequest('account/' . $this->account_id . '/rated/movies', $this->options); |
|
38 | 38 | |
39 | 39 | $this->page = (int) $response->page; |
40 | 40 | $this->total_pages = (int) $response->total_pages; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function getTVShows() : \Generator |
51 | 51 | { |
52 | - $response = $this->tmdb->getRequest('account/'.$this->account_id.'/rated/tv', $this->options); |
|
52 | + $response = $this->tmdb->getRequest('account/' . $this->account_id . '/rated/tv', $this->options); |
|
53 | 53 | |
54 | 54 | $this->page = (int) $response->page; |
55 | 55 | $this->total_pages = (int) $response->total_pages; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function getTVEpisodes() : \Generator |
66 | 66 | { |
67 | - $response = $this->tmdb->getRequest('account/'.$this->account_id.'/rated/tv/episodes', $this->options); |
|
67 | + $response = $this->tmdb->getRequest('account/' . $this->account_id . '/rated/tv/episodes', $this->options); |
|
68 | 68 | |
69 | 69 | $this->page = (int) $response->page; |
70 | 70 | $this->total_pages = (int) $response->total_pages; |
@@ -82,7 +82,6 @@ |
||
82 | 82 | return $this->markAsFavorite('movie', $movie_id, true); |
83 | 83 | } |
84 | 84 | /** |
85 | - |
|
86 | 85 | * Unmark a movie as favorite |
87 | 86 | * @param int $movie_id Movie id |
88 | 87 | * @return Favorite |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $params['media_id'] = $media_id; |
65 | 65 | $params['favorite'] = $favorite; |
66 | 66 | |
67 | - $this->tmdb->postRequest('account/'.$this->account_id.'/favorite', $this->options); |
|
67 | + $this->tmdb->postRequest('account/' . $this->account_id . '/favorite', $this->options); |
|
68 | 68 | |
69 | 69 | return $this; |
70 | 70 | } catch (TmdbException $e) { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | private function getAccountItems(string $item, string $result_class) : \Generator |
122 | 122 | { |
123 | - $response = $this->tmdb->getRequest('account/'.$this->account_id.'/favorite/'.$item, $this->options); |
|
123 | + $response = $this->tmdb->getRequest('account/' . $this->account_id . '/favorite/' . $item, $this->options); |
|
124 | 124 | |
125 | 125 | $this->page = (int) $response->page; |
126 | 126 | $this->total_pages = (int) $response->total_pages; |
@@ -58,7 +58,8 @@ discard block |
||
58 | 58 | */ |
59 | 59 | private function markAsFavorite(string $media_type, int $media_id, bool $favorite) : Favorite |
60 | 60 | { |
61 | - try { |
|
61 | + try |
|
62 | + { |
|
62 | 63 | $params = []; |
63 | 64 | $params['media_type'] = $media_type; |
64 | 65 | $params['media_id'] = $media_id; |
@@ -67,7 +68,9 @@ discard block |
||
67 | 68 | $this->tmdb->postRequest('account/'.$this->account_id.'/favorite', $this->options); |
68 | 69 | |
69 | 70 | return $this; |
70 | - } catch (TmdbException $e) { |
|
71 | + } |
|
72 | + catch (TmdbException $e) |
|
73 | + { |
|
71 | 74 | throw $e; |
72 | 75 | } |
73 | 76 | } |
@@ -92,7 +92,8 @@ |
||
92 | 92 | */ |
93 | 93 | public function checkDependency(BuilderInterface $builder) : bool |
94 | 94 | { |
95 | - if (!class_exists($builder->getMainClassName())) { |
|
95 | + if (!class_exists($builder->getMainClassName())) |
|
96 | + { |
|
96 | 97 | $message = "missing {$builder->getPackageName()}, please install it using composer : composer require {$builder->getPackageName()}"; |
97 | 98 | throw new MissingDependencyException($message); |
98 | 99 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | */ |
66 | 66 | public function getBuilder(string $builder, array $args = []) : LoggerBuilderInterface |
67 | 67 | { |
68 | - $class = "\\VfacTmdb\\Factory\\Builder\\{$builder}Builder"; |
|
68 | + $class = "\\VfacTmdb\\Factory\\Builder\\{$builder}builder"; |
|
69 | 69 | |
70 | 70 | $reflection = new \ReflectionClass($class); |
71 | 71 |
@@ -54,15 +54,20 @@ |
||
54 | 54 | */ |
55 | 55 | private function sendResponse(string $method, string $url, array $options = [], array $form_params = array()) |
56 | 56 | { |
57 | - try { |
|
57 | + try |
|
58 | + { |
|
58 | 59 | $params = array_merge($options, array('form_params' => $form_params)); |
59 | 60 | |
60 | 61 | return $this->guzzleClient->request($method, $url, $params); |
61 | - } catch (RequestException $e) { |
|
62 | - if (is_null($e->getResponse())) { |
|
62 | + } |
|
63 | + catch (RequestException $e) |
|
64 | + { |
|
65 | + if (is_null($e->getResponse())) |
|
66 | + { |
|
63 | 67 | throw new HttpErrorException; |
64 | 68 | } |
65 | - switch ((int) $e->getResponse()->getStatusCode()) { |
|
69 | + switch ((int) $e->getResponse()->getStatusCode()) |
|
70 | + { |
|
66 | 71 | case 404: |
67 | 72 | throw new NotFoundException($e->getMessage()); |
68 | 73 | default: |
@@ -149,12 +149,12 @@ |
||
149 | 149 | protected function sendRequest(string $method, string $url, array $form_params = array()) : ?\stdClass |
150 | 150 | { |
151 | 151 | switch ($method) { |
152 | - case 'GET': |
|
152 | + case 'GET': |
|
153 | 153 | $res = $this->http_request->getResponse($url); |
154 | - break; |
|
155 | - case 'POST': |
|
154 | + break; |
|
155 | + case 'POST': |
|
156 | 156 | $res = $this->http_request->postResponse($url, [], $form_params); |
157 | - break; |
|
157 | + break; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | $response = json_decode($res->getBody()); |
@@ -291,7 +291,7 @@ |
||
291 | 291 | default: |
292 | 292 | throw new IncorrectParamException; |
293 | 293 | } |
294 | - return 'created_at.'.$direction; |
|
294 | + return 'created_at.' . $direction; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -148,7 +148,8 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function sendRequest(string $method, string $url, array $form_params = array()) : ?\stdClass |
150 | 150 | { |
151 | - switch ($method) { |
|
151 | + switch ($method) |
|
152 | + { |
|
152 | 153 | case 'GET': |
153 | 154 | $res = $this->http_request->getResponse($url); |
154 | 155 | break; |
@@ -158,7 +159,8 @@ discard block |
||
158 | 159 | } |
159 | 160 | |
160 | 161 | $response = json_decode($res->getBody()); |
161 | - if (empty($response)) { |
|
162 | + if (empty($response)) |
|
163 | + { |
|
162 | 164 | $this->logger->error('Request Body can not be decode', array('url' => $url)); |
163 | 165 | throw new ServerErrorException(); |
164 | 166 | } |
@@ -195,14 +197,18 @@ discard block |
||
195 | 197 | */ |
196 | 198 | public function getConfiguration() : \stdClass |
197 | 199 | { |
198 | - try { |
|
200 | + try |
|
201 | + { |
|
199 | 202 | $this->logger->debug('Start getting configuration'); |
200 | - if (is_null($this->configuration)) { |
|
203 | + if (is_null($this->configuration)) |
|
204 | + { |
|
201 | 205 | $this->logger->debug('No configuration found, sending HTTP request to get it'); |
202 | 206 | $this->configuration = $this->getRequest('configuration'); |
203 | 207 | } |
204 | 208 | return $this->configuration; |
205 | - } catch (TmdbException $ex) { |
|
209 | + } |
|
210 | + catch (TmdbException $ex) |
|
211 | + { |
|
206 | 212 | throw $ex; |
207 | 213 | } |
208 | 214 | } |
@@ -221,8 +227,10 @@ discard block |
||
221 | 227 | $params['include_adult'] = $this->include_adult; |
222 | 228 | $params['page'] = $this->page; |
223 | 229 | // Check options |
224 | - foreach ($options as $key => $value) { |
|
225 | - switch ($key) { |
|
230 | + foreach ($options as $key => $value) |
|
231 | + { |
|
232 | + switch ($key) |
|
233 | + { |
|
226 | 234 | case 'year': |
227 | 235 | $params[$key] = $this->checkYear($value); |
228 | 236 | break; |
@@ -269,7 +277,8 @@ discard block |
||
269 | 277 | private function checkLanguage(string $language) : string |
270 | 278 | { |
271 | 279 | $check = preg_match("#([a-z]{2})-([A-Z]{2})#", $language); |
272 | - if ($check === 0 || $check === false) { |
|
280 | + if ($check === 0 || $check === false) |
|
281 | + { |
|
273 | 282 | $this->logger->error('Incorrect language param option', array('language' => $language)); |
274 | 283 | throw new IncorrectParamException; |
275 | 284 | } |
@@ -284,7 +293,8 @@ discard block |
||
284 | 293 | */ |
285 | 294 | private function checkSort(string $direction) : string |
286 | 295 | { |
287 | - switch ($direction) { |
|
296 | + switch ($direction) |
|
297 | + { |
|
288 | 298 | case 'asc': |
289 | 299 | case 'desc': |
290 | 300 | break; |
@@ -310,7 +320,8 @@ discard block |
||
310 | 320 | */ |
311 | 321 | public function __get(string $name) : string |
312 | 322 | { |
313 | - switch ($name) { |
|
323 | + switch ($name) |
|
324 | + { |
|
314 | 325 | case 'url': |
315 | 326 | return $this->$name; |
316 | 327 | default: |
@@ -61,10 +61,12 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private function searchItem(string $item, string $query, array $options, string $result_class) : \Generator |
63 | 63 | { |
64 | - try { |
|
64 | + try |
|
65 | + { |
|
65 | 66 | $this->logger->debug('Starting search item', array('item' => $item, 'query' => $query, 'options' => $options, 'result_class' => $result_class)); |
66 | 67 | $query = trim($query); |
67 | - if (empty($query)) { |
|
68 | + if (empty($query)) |
|
69 | + { |
|
68 | 70 | $this->logger->error('Query param cannot be empty', array('item' => $item, 'query' => $query, 'options' => $options, 'result_class' => $result_class)); |
69 | 71 | throw new IncorrectParamException; |
70 | 72 | } |
@@ -77,7 +79,9 @@ discard block |
||
77 | 79 | $this->total_results = (int) $response->total_results; |
78 | 80 | |
79 | 81 | return $this->searchItemGenerator($response->results, $result_class); |
80 | - } catch (TmdbException $ex) { |
|
82 | + } |
|
83 | + catch (TmdbException $ex) |
|
84 | + { |
|
81 | 85 | throw $ex; |
82 | 86 | } |
83 | 87 | } |
@@ -90,7 +94,8 @@ discard block |
||
90 | 94 | private function searchItemGenerator(array $results, string $class) |
91 | 95 | { |
92 | 96 | $this->logger->debug('Starting search item generator', array('results' => $results, 'class' => $class)); |
93 | - foreach ($results as $result) { |
|
97 | + foreach ($results as $result) |
|
98 | + { |
|
94 | 99 | $element = new $class($this->tmdb, $result); |
95 | 100 | |
96 | 101 | yield $element; |
@@ -106,10 +111,13 @@ discard block |
||
106 | 111 | */ |
107 | 112 | public function movie(string $query, array $options = array()) : \Generator |
108 | 113 | { |
109 | - try { |
|
114 | + try |
|
115 | + { |
|
110 | 116 | $this->logger->debug('Starting search movie', array('query' => $query, 'options' => $options)); |
111 | 117 | return $this->searchItem('movie', $query, $options, Results\Movie::class); |
112 | - } catch (TmdbException $ex) { |
|
118 | + } |
|
119 | + catch (TmdbException $ex) |
|
120 | + { |
|
113 | 121 | throw $ex; |
114 | 122 | } |
115 | 123 | } |
@@ -123,10 +131,13 @@ discard block |
||
123 | 131 | */ |
124 | 132 | public function tvshow(string $query, array $options = array()) : \Generator |
125 | 133 | { |
126 | - try { |
|
134 | + try |
|
135 | + { |
|
127 | 136 | $this->logger->debug('Starting search tv show', array('query' => $query, 'options' => $options)); |
128 | 137 | return $this->searchItem('tv', $query, $options, Results\TVShow::class); |
129 | - } catch (TmdbException $ex) { |
|
138 | + } |
|
139 | + catch (TmdbException $ex) |
|
140 | + { |
|
130 | 141 | throw $ex; |
131 | 142 | } |
132 | 143 | } |
@@ -140,10 +151,13 @@ discard block |
||
140 | 151 | */ |
141 | 152 | public function collection(string $query, array $options = array()) : \Generator |
142 | 153 | { |
143 | - try { |
|
154 | + try |
|
155 | + { |
|
144 | 156 | $this->logger->debug('Starting search collection', array('query' => $query, 'options' => $options)); |
145 | 157 | return $this->searchItem('collection', $query, $options, Results\Collection::class); |
146 | - } catch (TmdbException $ex) { |
|
158 | + } |
|
159 | + catch (TmdbException $ex) |
|
160 | + { |
|
147 | 161 | throw $ex; |
148 | 162 | } |
149 | 163 | } |
@@ -157,10 +171,13 @@ discard block |
||
157 | 171 | */ |
158 | 172 | public function people(string $query, array $options = array()) : \Generator |
159 | 173 | { |
160 | - try { |
|
174 | + try |
|
175 | + { |
|
161 | 176 | $this->logger->debug('Starting search people', array('query' => $query, 'options' => $options)); |
162 | 177 | return $this->searchItem('person', $query, $options, Results\People::class); |
163 | - } catch (TmdbException $ex) { |
|
178 | + } |
|
179 | + catch (TmdbException $ex) |
|
180 | + { |
|
164 | 181 | throw $ex; |
165 | 182 | } |
166 | 183 | } |
@@ -174,10 +191,13 @@ discard block |
||
174 | 191 | */ |
175 | 192 | public function company(string $query, array $options = array()) : \Generator |
176 | 193 | { |
177 | - try { |
|
194 | + try |
|
195 | + { |
|
178 | 196 | $this->logger->debug('Starting search company', array('query' => $query, 'options' => $options)); |
179 | 197 | return $this->searchItem('company', $query, $options, Results\Company::class); |
180 | - } catch (TmdbException $ex) { |
|
198 | + } |
|
199 | + catch (TmdbException $ex) |
|
200 | + { |
|
181 | 201 | throw $ex; |
182 | 202 | } |
183 | 203 | } |
@@ -29,7 +29,8 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function getPosterPath() : string |
31 | 31 | { |
32 | - if (isset($this->data->poster_path)) { |
|
32 | + if (isset($this->data->poster_path)) |
|
33 | + { |
|
33 | 34 | return $this->data->poster_path; |
34 | 35 | } |
35 | 36 | return ''; |
@@ -41,7 +42,8 @@ discard block |
||
41 | 42 | */ |
42 | 43 | public function getBackdropPath() : string |
43 | 44 | { |
44 | - if (isset($this->data->backdrop_path)) { |
|
45 | + if (isset($this->data->backdrop_path)) |
|
46 | + { |
|
45 | 47 | return $this->data->backdrop_path; |
46 | 48 | } |
47 | 49 | return ''; |
@@ -66,14 +66,17 @@ |
||
66 | 66 | */ |
67 | 67 | public function __construct(TmdbInterface $tmdb, int $item_id, array $options, string $item_name) |
68 | 68 | { |
69 | - try { |
|
69 | + try |
|
70 | + { |
|
70 | 71 | $this->id = $item_id; |
71 | 72 | $this->tmdb = $tmdb; |
72 | 73 | $this->logger = $tmdb->getLogger(); |
73 | 74 | $this->conf = $this->tmdb->getConfiguration(); |
74 | 75 | $this->params = $this->tmdb->checkOptions($options); |
75 | 76 | $this->data = $this->tmdb->getRequest($item_name . '/' . (int) $item_id, $this->params); |
76 | - } catch (TmdbException $ex) { |
|
77 | + } |
|
78 | + catch (TmdbException $ex) |
|
79 | + { |
|
77 | 80 | throw $ex; |
78 | 81 | } |
79 | 82 | } |
@@ -65,7 +65,8 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function __construct(TmdbInterface $tmdb, AuthInterface $auth, int $account_id, array $options = array()) |
67 | 67 | { |
68 | - if (trim($auth->session_id) == '') { |
|
68 | + if (trim($auth->session_id) == '') |
|
69 | + { |
|
69 | 70 | throw new ServerErrorException('No account session found'); |
70 | 71 | } |
71 | 72 | $this->tmdb = $tmdb; |
@@ -85,7 +86,8 @@ discard block |
||
85 | 86 | protected function searchItemGenerator(array $results, string $class) : \Generator |
86 | 87 | { |
87 | 88 | $this->logger->debug('Starting search item generator', array('results' => $results, 'class' => $class)); |
88 | - foreach ($results as $result) { |
|
89 | + foreach ($results as $result) |
|
90 | + { |
|
89 | 91 | $element = new $class($this->tmdb, $result); |
90 | 92 | |
91 | 93 | yield $element; |