ReviewOS

also looking at this

meemalabs/meema-client-php

Exceptions

#27
Merged glennmichael123 wants to merge exceptions into main
5 files +168 -14
src/Models/Folder.phpmodified+58-5
Changes to src/Models/Folder.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 Folder
@@ -47,7 +48,9 @@ class Folder
4748 *
4849 * @param int $id
4950 *
50 * @return array
51 * @return mixed
52 *
53 * @throws InvalidFormatException
5154 */
5255 public function get($id = null)
5356 {
@@ -55,6 +58,10 @@ class Folder
5558 return $this->all();
5659 }
5760
61 if (! is_int($id)) {
62 throw new InvalidFormatException();
63 }
64
5865 $ids = is_array($id) ? $id : func_get_args();
5966
6067 return $this->client->request('GET', 'folders', ['folder_ids' => $ids]);
@@ -66,9 +73,15 @@ class Folder
6673 * @param int $id
6774 *
6875 * @return Response
76 *
77 * @throws InvalidFormatException
6978 */
70 public function find($id): Response
79 public function find($id)
7180 {
81 if (! is_int($id)) {
82 throw new InvalidFormatException();
83 }
84
7285 $response = $this->client->request('GET', "folders/${id}");
7386
7487 return new Response($this, $response);
@@ -97,13 +110,17 @@ class Folder
97110 /**
98111 * Update folder.
99112 *
100 * @param string $name
101113 * @param int $id
114 * @param string $name
102115 *
103116 * @return array
104117 */
105118 public function update($id, $name): array
106119 {
120 if (! is_int($id)) {
121 throw new InvalidFormatException();
122 }
123
107124 $name = is_array($name) ? $name : compact('name');
108125
109126 return $this->client->request('PATCH', "folders/{$id}", $name);
@@ -115,9 +132,15 @@ class Folder
115132 * @param int $id
116133 *
117134 * @return null
135 *
136 * @throws InvalidFormatException
118137 */
119138 public function delete($id)
120139 {
140 if (! is_int($id)) {
141 throw new InvalidFormatException();
142 }
143
121144 if ($this->model) {
122145 return $this->deleteFolderFromMedia($this->model->getId(), $id);
123146 }
@@ -143,9 +166,15 @@ class Folder
143166 * @param int $id
144167 *
145168 * @return array
169 *
170 * @throws InvalidFormatException
146171 */
147 public function archive($id): array
172 public function archive($id)
148173 {
174 if (! is_int($id)) {
175 throw new InvalidFormatException();
176 }
177
149178 return $this->client->request('POST', "folders/{$id}/archive");
150179 }
151180
@@ -155,9 +184,15 @@ class Folder
155184 * @param int $id
156185 *
157186 * @return array
187 *
188 * @throws InvalidFormatException
158189 */
159 public function unarchive($id): array
190 public function unarchive($id)
160191 {
192 if (! is_int($id)) {
193 throw new InvalidFormatException();
194 }
195
161196 return $this->client->request('POST', "folders/{$id}/unarchive");
162197 }
163198
@@ -167,9 +202,15 @@ class Folder
167202 * @param int $id
168203 *
169204 * @return array
205 *
206 * @throws InvalidFormatException
170207 */
171208 public function duplicate($id): array
172209 {
210 if (! is_int($id)) {
211 throw new InvalidFormatException();
212 }
213
173214 return $this->client->request('POST', "folders/{$id}/duplicate");
174215 }
175216
@@ -179,9 +220,15 @@ class Folder
179220 * @param int $id
180221 *
181222 * @return array
223 *
224 * @throws InvalidFormatException
182225 */
183226 public function addFolderToMedia($id, $name): array
184227 {
228 if (! is_int($id)) {
229 throw new InvalidFormatException();
230 }
231
185232 return $this->client->request('POST', "media/{$id}/folders", $name);
186233 }
187234
@@ -192,9 +239,15 @@ class Folder
192239 * @param int $folderId
193240 *
194241 * @return null
242 *
243 * @throws InvalidFormatException
195244 */
196245 public function deleteFolderFromMedia($id, $folderId)
197246 {
247 if (! is_int($id) || ! is_int($folderId)) {
248 throw new InvalidFormatException();
249 }
250
198251 return $this->client->request('DELETE', "media/{$id}/folders/{$folderId}");
199252 }
200253