ReviewOS

also looking at this

meemalabs/meema-client-php

Exceptions

#27
Merged glennmichael123 wants to merge exceptions into main
5 files +168 -14

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

src/Models/Favorite.phpmodified+17-0
Changes to src/Models/Favorite.php
@@ -3,6 +3,7 @@
33namespace Meema\MeemaApi\Models;
44
55use Meema\MeemaApi\Client;
6use Meema\MeemaApi\Exceptions\InvalidFormatException;
67use Meema\MeemaApi\Response\Response;
78
89class Favorite
@@ -50,6 +51,10 @@ class Favorite
5051 return $this->all();
5152 }
5253
54 if (! is_int($id)) {
55 throw new InvalidFormatException();
56 }
57
5358 $ids = is_array($id) ? $id : func_get_args();
5459
5560 return $this->client->request('GET', 'favorites', ['favorite_ids' => $ids]);
@@ -64,6 +69,10 @@ class Favorite
6469 */
6570 public function find($id)
6671 {
72 if (! is_int($id)) {
73 throw new InvalidFormatException();
74 }
75
6776 $response = $this->client->request('GET', "favorites/${id}");
6877
6978 return new Response($this, $response);
@@ -91,6 +100,10 @@ class Favorite
91100 */
92101 public function update($id, $data): array
93102 {
103 if (! is_int($id)) {
104 throw new InvalidFormatException();
105 }
106
94107 return $this->client->request('PATCH', "favorites/{$id}", $data);
95108 }
96109
@@ -103,6 +116,10 @@ class Favorite
103116 */
104117 public function delete($id)
105118 {
119 if (! is_int($id)) {
120 throw new InvalidFormatException();
121 }
122
106123 return $this->client->request('DELETE', "favorites/{$id}");
107124 }
108125}
src/Models/Folder.phpmodified+40-76
Changes to src/Models/Folder.php
@@ -58,16 +58,12 @@ class Folder
5858 return $this->all();
5959 }
6060
61 try {
62 if (! is_int($id)) {
63 throw new InvalidFormatException();
64 }
65
66 $ids = is_array($id) ? $id : func_get_args();
67 } catch (InvalidFormatException $e) {
68 return $e->getMessage();
61 if (! is_int($id)) {
62 throw new InvalidFormatException();
6963 }
7064
65 $ids = is_array($id) ? $id : func_get_args();
66
7167 return $this->client->request('GET', 'folders', ['folder_ids' => $ids]);
7268 }
7369
@@ -82,16 +78,12 @@ class Folder
8278 */
8379 public function find($id)
8480 {
85 try {
86 if (! is_int($id)) {
87 throw new InvalidFormatException();
88 }
89
90 $response = $this->client->request('GET', "folders/${id}");
91 } catch (InvalidFormatException $e) {
92 return $e->getMessage();
81 if (! is_int($id)) {
82 throw new InvalidFormatException();
9383 }
9484
85 $response = $this->client->request('GET', "folders/${id}");
86
9587 return new Response($this, $response);
9688 }
9789
@@ -124,17 +116,13 @@ class Folder
124116 * @return array
125117 */
126118 public function update($id, $name): array
127 {
128 try {
129 if (! is_int($id)) {
130 throw new InvalidFormatException();
131 }
132
133 $name = is_array($name) ? $name : compact('name');
134 } catch (InvalidFormatException $e) {
135 return $e->getMessage();
119{
120 if (! is_int($id)) {
121 throw new InvalidFormatException();
136122 }
137123
124 $name = is_array($name) ? $name : compact('name');
125
138126 return $this->client->request('PATCH', "folders/{$id}", $name);
139127 }
140128
@@ -149,16 +137,12 @@ class Folder
149137 */
150138 public function delete($id)
151139 {
152 try {
153 if (! is_int($id)) {
154 throw new InvalidFormatException();
155 }
156
157 if ($this->model) {
158 return $this->deleteFolderFromMedia($this->model->getId(), $id);
159 }
160 } catch (InvalidFormatException $e) {
161 return $e->getMessage();
140 if (! is_int($id)) {
141 throw new InvalidFormatException();
142 }
143
144 if ($this->model) {
145 return $this->deleteFolderFromMedia($this->model->getId(), $id);
162146 }
163147
164148 return $this->client->request('DELETE', "folders/{$id}");
@@ -186,16 +170,12 @@ class Folder
186170 * @throws InvalidFormatException
187171 */
188172 public function archive($id)
189 {
190 try {
191 if (! is_int($id)) {
192 throw new InvalidFormatException();
193 }
194
195 return $this->client->request('POST', "folders/{$id}/archive");
196 } catch (InvalidFormatException $e) {
197 return $e->getMessage();
173{
174 if (! is_int($id)) {
175 throw new InvalidFormatException();
198176 }
177
178 return $this->client->request('POST', "folders/{$id}/archive");
199179 }
200180
201181 /**
@@ -209,15 +189,11 @@ class Folder
209189 */
210190 public function unarchive($id)
211191 {
212 try {
213 if (! is_int($id)) {
214 throw new InvalidFormatException();
215 }
216
217 return $this->client->request('POST', "folders/{$id}/unarchive");
218 } catch (InvalidFormatException $e) {
219 return $e->getMessage();
192 if (! is_int($id)) {
193 throw new InvalidFormatException();
220194 }
195
196 return $this->client->request('POST', "folders/{$id}/unarchive");
221197 }
222198
223199 /**
@@ -231,15 +207,11 @@ class Folder
231207 */
232208 public function duplicate($id): array
233209 {
234 try {
235 if (! is_int($id)) {
236 throw new InvalidFormatException();
237 }
238
239 return $this->client->request('POST', "folders/{$id}/duplicate");
240 } catch (InvalidFormatException $e) {
241 return $e->getMessage();
210 if (! is_int($id)) {
211 throw new InvalidFormatException();
242212 }
213
214 return $this->client->request('POST', "folders/{$id}/duplicate");
243215 }
244216
245217 /**
@@ -253,15 +225,11 @@ class Folder
253225 */
254226 public function addFolderToMedia($id, $name): array
255227 {
256 try {
257 if (! is_int($id)) {
258 throw new InvalidFormatException();
259 }
260
261 return $this->client->request('POST', "media/{$id}/folders", $name);
262 } catch (InvalidFormatException $e) {
263 return $e->getMessage();
228 if (! is_int($id)) {
229 throw new InvalidFormatException();
264230 }
231
232 return $this->client->request('POST', "media/{$id}/folders", $name);
265233 }
266234
267235 /**
@@ -276,15 +244,11 @@ class Folder
276244 */
277245 public function deleteFolderFromMedia($id, $folderId)
278246 {
279 try {
280 if (! is_int($id) || ! is_int($folderId)) {
281 throw new InvalidFormatException();
282 }
283
284 return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}");
285 } catch (InvalidFormatException $e) {
286 return $e->getMessage();
247 if (! is_int($id) || ! is_int($folderId)) {
248 throw new InvalidFormatException();
287249 }
250
251 return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}");
288252 }
289253
290254 /**
src/Models/Media.phpmodified+37-73
Changes to src/Models/Media.php
@@ -60,16 +60,12 @@ class Media
6060 return $this->all();
6161 }
6262
63 try {
64 if (! is_int($id)) {
65 throw new InvalidFormatException();
66 }
67
68 $ids = is_array($id) ? $id : func_get_args();
69 } catch (InvalidFormatException $e) {
70 return $e->getMessage();
63 if (! is_int($id)) {
64 throw new InvalidFormatException();
7165 }
7266
67 $ids = is_array($id) ? $id : func_get_args();
68
7369 return $this->client->request('GET', 'media', ['media_ids' => $ids]);
7470 }
7571
@@ -84,16 +80,12 @@ class Media
8480 */
8581 public function find($id)
8682 {
87 try {
88 if (! is_int($id)) {
89 throw new InvalidFormatException();
90 }
91
92 $response = $this->client->request('GET', "media/${id}");
93 } catch (InvalidFormatException $e) {
94 return $e->getMessage();
83 if (! is_int($id)) {
84 throw new InvalidFormatException();
9585 }
9686
87 $response = $this->client->request('GET', "media/${id}");
88
9789 return new Response($this, $response);
9890 }
9991
@@ -123,17 +115,13 @@ class Media
123115 */
124116 public function update($id, $name)
125117 {
126 try {
127 if (! is_int($id)) {
128 throw new InvalidFormatException();
129 }
118 if (! is_int($id)) {
119 throw new InvalidFormatException();
120 }
130121
131 $name = is_array($name) ? $name : compact('name');
122 $name = is_array($name) ? $name : compact('name');
132123
133 return $this->client->request('PATCH', "media/{$id}/file-name", $name);
134 } catch (InvalidFormatException $e) {
135 return $e->getMessage();
136 }
124 return $this->client->request('PATCH', "media/{$id}/file-name", $name);
137125 }
138126
139127 /**
@@ -147,15 +135,11 @@ class Media
147135 */
148136 public function delete($id)
149137 {
150 try {
151 if (! is_int($id)) {
152 throw new InvalidFormatException();
153 }
154
155 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
156 } catch (InvalidFormatException $e) {
157 return $e->getMessage();
138 if (! is_int($id)) {
139 throw new InvalidFormatException();
158140 }
141
142 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
159143 }
160144
161145 /**
@@ -181,15 +165,11 @@ class Media
181165 */
182166 public function archive($id)
183167 {
184 try {
185 if (! is_int($id)) {
186 throw new InvalidFormatException();
187 }
188
189 return $this->client->request('POST', "media/{$id}/archive");
190 } catch (InvalidFormatException $e) {
191 return $e->getMessage();
168 if (! is_int($id)) {
169 throw new InvalidFormatException();
192170 }
171
172 return $this->client->request('POST', "media/{$id}/archive");
193173 }
194174
195175 /**
@@ -203,15 +183,11 @@ class Media
203183 */
204184 public function unarchive($id)
205185 {
206 try {
207 if (! is_int($id)) {
208 throw new InvalidFormatException();
209 }
210
211 return $this->client->request('POST', "media/{$id}/unarchive");
212 } catch (InvalidFormatException $e) {
213 return $e->getMessage();
186 if (! is_int($id)) {
187 throw new InvalidFormatException();
214188 }
189
190 return $this->client->request('POST', "media/{$id}/unarchive");
215191 }
216192
217193 /**
@@ -225,15 +201,11 @@ class Media
225201 */
226202 public function makePrivate($id)
227203 {
228 try {
229 if (! is_int($id)) {
230 throw new InvalidFormatException();
231 }
232
233 return $this->client->request('PATCH', "media/{$id}/make-private");
234 } catch (InvalidFormatException $e) {
235 return $e->getMessage();
204 if (! is_int($id)) {
205 throw new InvalidFormatException();
236206 }
207
208 return $this->client->request('PATCH', "media/{$id}/make-private");
237209 }
238210
239211 /**
@@ -247,15 +219,11 @@ class Media
247219 */
248220 public function makePublic($id)
249221 {
250 try {
251 if (! is_int($id)) {
252 throw new InvalidFormatException();
253 }
254
255 return $this->client->request('PATCH', "media/{$id}/make-public");
256 } catch (InvalidFormatException $e) {
257 return $e->getMessage();
222 if (! is_int($id)) {
223 throw new InvalidFormatException();
258224 }
225
226 return $this->client->request('PATCH', "media/{$id}/make-public");
259227 }
260228
261229 /**
@@ -269,15 +237,11 @@ class Media
269237 */
270238 public function duplicate($id)
271239 {
272 try {
273 if (! is_int($id)) {
274 throw new InvalidFormatException();
275 }
276
277 return $this->client->request('POST', "media/{$id}/duplicate");
278 } catch (InvalidFormatException $e) {
279 return $e->getMessage();
240 if (! is_int($id)) {
241 throw new InvalidFormatException();
280242 }
243
244 return $this->client->request('POST', "media/{$id}/duplicate");
281245 }
282246
283247 /**
src/Models/Tag.phpmodified+17-0
Changes to src/Models/Tag.php
@@ -3,6 +3,7 @@
33namespace Meema\MeemaApi\Models;
44
55use Meema\MeemaApi\Client;
6use Meema\MeemaApi\Exceptions\InvalidFormatException;
67use Meema\MeemaApi\Response\Response;
78
89class Tag
@@ -59,6 +60,10 @@ class Tag
5960 return $this->all();
6061 }
6162
63 if (! is_int($id)) {
64 throw new InvalidFormatException();
65 }
66
6267 $ids = is_array($id) ? $id : func_get_args();
6368
6469 return $this->client->request('GET', 'tags', ['tag_ids' => $ids]);
@@ -73,6 +78,10 @@ class Tag
7378 */
7479 public function find($id): Response
7580 {
81 if (! is_int($id)) {
82 throw new InvalidFormatException();
83 }
84
7685 $response = $this->client->request('GET', "tags/${id}");
7786
7887 return new Response($this, $response);
@@ -102,6 +111,10 @@ class Tag
102111 */
103112 public function update($id, $data): array
104113 {
114 if (! is_int($id)) {
115 throw new InvalidFormatException();
116 }
117
105118 return $this->client->request('PATCH', 'tags/color', $data);
106119 }
107120
@@ -114,6 +127,10 @@ class Tag
114127 */
115128 public function delete($id)
116129 {
130 if (! is_int($id)) {
131 throw new InvalidFormatException();
132 }
133
117134 return $this->client->request('DELETE', "tags/{$id}");
118135 }
119136