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/Media.phpmodified+106-15
Changes to src/Models/Media.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 Media
@@ -46,6 +47,8 @@ class Media
4647 * Get specific media.
4748 *
4849 * @return array
50 *
51 * @throws InvalidFormatException
4952 */
5053 public function get($id = null)
5154 {
@@ -57,7 +60,15 @@ class Media
5760 return $this->all();
5861 }
5962
60 $ids = is_array($id) ? $id : func_get_args();
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->errorMessage();
71 }
6172
6273 return $this->client->request('GET', 'media/show', ['media_ids' => $ids]);
6374 }
@@ -68,10 +79,20 @@ class Media
6879 * @param int $id
6980 *
7081 * @return array
82 *
83 * @throws InvalidFormatException
7184 */
7285 public function find($id)
7386 {
74 $response = $this->client->request('GET', "media/${id}");
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->errorMessage();
95 }
7596
7697 return new Response($this, $response);
7798 }
@@ -97,12 +118,22 @@ class Media
97118 * @param string $name
98119 *
99120 * @return array
121 *
122 * @throws InvalidFormatException
100123 */
101 public function update($id, $name): array
124 public function update($id, $name)
102125 {
103 $name = is_array($name) ? $name : compact('name');
126 try {
127 if (! is_int($id)) {
128 throw new InvalidFormatException();
129 }
130
131 $name = is_array($name) ? $name : compact('name');
104132
105 return $this->client->request('PATCH', "media/{$id}/file-name", $name);
133 return $this->client->request('PATCH', "media/{$id}/file-name", $name);
134 } catch (InvalidFormatException $e) {
135 return $e->errorMessage();
136 }
106137 }
107138
108139 /**
@@ -111,10 +142,20 @@ class Media
111142 * @param int $id
112143 *
113144 * @return null
145 *
146 * @throws InvalidFormatException
114147 */
115 public function delete($id = null)
148 public function delete($id)
116149 {
117 return $this->client->request('DELETE', "media/{$id}", ['media_id' => $id]);
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->errorMessage();
158 }
118159 }
119160
120161 /**
@@ -135,10 +176,20 @@ class Media
135176 * @param int $id
136177 *
137178 * @return array
179 *
180 * @throws InvalidFormatException
138181 */
139 public function archive($id = null): array
182 public function archive($id)
140183 {
141 return $this->client->request('POST', "media/{$id}/archive");
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->errorMessage();
192 }
142193 }
143194
144195 /**
@@ -147,10 +198,20 @@ class Media
147198 * @param int $id
148199 *
149200 * @return array
201 *
202 * @throws InvalidFormatException
150203 */
151 public function unarchive($id): array
204 public function unarchive($id)
152205 {
153 return $this->client->request('POST', "media/{$id}/unarchive");
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->errorMessage();
214 }
154215 }
155216
156217 /**
@@ -159,10 +220,20 @@ class Media
159220 * @param int $id
160221 *
161222 * @return array
223 *
224 * @throws InvalidFormatException
162225 */
163226 public function makePrivate($id): array
164227 {
165 return $this->client->request('PATCH', "media/{$id}/make-private");
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->errorMessage();
236 }
166237 }
167238
168239 /**
@@ -171,10 +242,20 @@ class Media
171242 * @param int $id
172243 *
173244 * @return array
245 *
246 * @throws InvalidFormatException
174247 */
175 public function makePublic($id): array
248 public function makePublic($id)
176249 {
177 return $this->client->request('PATCH', "media/{$id}/make-public");
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->errorMessage();
258 }
178259 }
179260
180261 /**
@@ -183,10 +264,20 @@ class Media
183264 * @param int $id
184265 *
185266 * @return array
267 *
268 * @throws InvalidFormatException
186269 */
187270 public function duplicate($id): array
188271 {
189 return $this->client->request('POST', "media/{$id}/duplicate");
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->errorMessage();
280 }
190281 }
191282
192283 /**