1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Tmdb package. |
4
|
|
|
* |
5
|
|
|
* (c) Vincent Faliès <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @author Vincent Faliès <[email protected]> |
11
|
|
|
* @copyright Copyright (c) 2017 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
namespace VfacTmdb\Account; |
16
|
|
|
|
17
|
|
|
use VfacTmdb\Results; |
18
|
|
|
use VfacTmdb\Exceptions\TmdbException; |
19
|
|
|
use VfacTmdb\Traits\ListItems; |
20
|
|
|
use VfacTmdb\Abstracts\Account; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class to manipulate account rated |
24
|
|
|
* @package Tmdb |
25
|
|
|
* @author Vincent Faliès <[email protected]> |
26
|
|
|
* @copyright Copyright (c) 2017 |
27
|
|
|
*/ |
28
|
|
|
class Rated extends Account |
29
|
|
|
{ |
30
|
|
|
use ListItems; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get movies rated |
34
|
|
|
* @return \Generator|Results\Movie |
35
|
|
|
*/ |
36
|
1 |
View Code Duplication |
public function getMovies() : \Generator |
|
|
|
|
37
|
|
|
{ |
38
|
1 |
|
$response = $this->tmdb->getRequest('account/'.$this->account_id.'/rated/movies', $this->options); |
39
|
|
|
|
40
|
1 |
|
$this->page = (int) $response->page; |
41
|
1 |
|
$this->total_pages = (int) $response->total_pages; |
42
|
1 |
|
$this->total_results = (int) $response->total_results; |
43
|
|
|
|
44
|
1 |
|
return $this->searchItemGenerator($response->results, Results\Movie::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get TV shows rated |
49
|
|
|
* @return \Generator|Results\TVShow |
50
|
|
|
*/ |
51
|
1 |
View Code Duplication |
public function getTVShows() : \Generator |
|
|
|
|
52
|
|
|
{ |
53
|
1 |
|
$response = $this->tmdb->getRequest('account/'.$this->account_id.'/rated/tv', $this->options); |
54
|
|
|
|
55
|
1 |
|
$this->page = (int) $response->page; |
56
|
1 |
|
$this->total_pages = (int) $response->total_pages; |
57
|
1 |
|
$this->total_results = (int) $response->total_results; |
58
|
|
|
|
59
|
1 |
|
return $this->searchItemGenerator($response->results, Results\TVShow::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get TV episodes rated |
64
|
|
|
* @return \Generator|Results\TVEpisode |
65
|
|
|
*/ |
66
|
1 |
View Code Duplication |
public function getTVEpisodes() : \Generator |
|
|
|
|
67
|
|
|
{ |
68
|
1 |
|
$response = $this->tmdb->getRequest('account/'.$this->account_id.'/rated/tv/episodes', $this->options); |
69
|
|
|
|
70
|
1 |
|
$this->page = (int) $response->page; |
71
|
1 |
|
$this->total_pages = (int) $response->total_pages; |
72
|
1 |
|
$this->total_results = (int) $response->total_results; |
73
|
|
|
|
74
|
1 |
|
return $this->searchItemGenerator($response->results, Results\TVEpisode::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Add movie rate |
79
|
|
|
* @param int $movie_id |
80
|
|
|
* @param float $rate |
81
|
|
|
* @return Rated |
82
|
|
|
*/ |
83
|
2 |
|
public function addMovieRate(int $movie_id, float $rate) : Rated |
84
|
|
|
{ |
85
|
2 |
|
return $this->addRate('movie/'.$movie_id.'/rating', $rate); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Remove movie rate |
90
|
|
|
* @param int $movie_id |
91
|
|
|
* @return Rated |
92
|
|
|
*/ |
93
|
2 |
|
public function removeMovieRate(int $movie_id) : Rated |
94
|
|
|
{ |
95
|
2 |
|
return $this->removeRate('movie/'.$movie_id.'/rating'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Add TVShow rate |
100
|
|
|
* @param int $tv_id |
101
|
|
|
* @param float $rate |
102
|
|
|
* @return Rated |
103
|
|
|
*/ |
104
|
1 |
|
public function addTVShowRate(int $tv_id, float $rate) : Rated |
105
|
|
|
{ |
106
|
1 |
|
return $this->addRate('tv/'.$tv_id.'/rating', $rate); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Remove TVShow rate |
111
|
|
|
* @param int $tv_id |
112
|
|
|
* @return Rated |
113
|
|
|
*/ |
114
|
1 |
|
public function removeTVShowRate(int $tv_id) : Rated |
115
|
|
|
{ |
116
|
1 |
|
return $this->removeRate('tv/'.$tv_id.'/rating'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Add TVShow episode rate |
121
|
|
|
* @param int $tv_id |
122
|
|
|
* @param int $season_number |
123
|
|
|
* @param int $episode_number |
124
|
|
|
* @param float $rate |
125
|
|
|
* @return Rated |
126
|
|
|
*/ |
127
|
1 |
|
public function addTVShowEpisodeRate(int $tv_id, int $season_number, int $episode_number, float $rate) : Rated |
128
|
|
|
{ |
129
|
1 |
|
return $this->addRate('tv/'.$tv_id.'/season/'.$season_number.'/episode/'.$episode_number.'/rating', $rate); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Remove TVSHow episode rate |
134
|
|
|
* @param int $tv_id |
135
|
|
|
* @param int $season_number |
136
|
|
|
* @param int $episode_number |
137
|
|
|
* @return Rated |
138
|
|
|
*/ |
139
|
1 |
|
public function removeTVShowEpisodeRate(int $tv_id, int $season_number, int $episode_number) : Rated |
140
|
|
|
{ |
141
|
1 |
|
return $this->removeRate('tv/'.$tv_id.'/season/'.$season_number.'/episode/'.$episode_number.'/rating'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Add rate |
146
|
|
|
* @param string $action uri action |
147
|
|
|
* @param float $rate |
148
|
|
|
* @return Rated |
149
|
|
|
*/ |
150
|
4 |
|
private function addRate(string $action, float $rate) : Rated |
151
|
|
|
{ |
152
|
|
|
try { |
153
|
4 |
|
$params = []; |
154
|
4 |
|
$params['value'] = $rate; |
155
|
|
|
|
156
|
4 |
|
$this->tmdb->postRequest($action, $this->options, $params); |
|
|
|
|
157
|
|
|
|
158
|
3 |
|
return $this; |
159
|
1 |
|
} catch (TmdbException $e) { |
160
|
1 |
|
throw $e; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Remove Rate |
166
|
|
|
* @param string $action uri action |
167
|
|
|
* @return Rated |
168
|
|
|
*/ |
169
|
4 |
|
private function removeRate(string $action) : Rated |
170
|
|
|
{ |
171
|
|
|
try { |
172
|
4 |
|
$this->tmdb->deleteRequest($action, $this->options); |
173
|
|
|
|
174
|
3 |
|
return $this; |
175
|
1 |
|
} catch (TmdbException $e) { |
176
|
1 |
|
throw $e; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.