ReviewOS

also looking at this

meemalabs/meema-client-php

fix: Only use uuid for media and check for validity

#78
Merged glennmichael123 wants to merge media-uuid into main
11 files +65 -32
src/Models/Media.phpmodified+20-19
Changes to src/Models/Media.php
@@ -6,10 +6,11 @@ use Meema\MeemaClient\Client;
66use Meema\MeemaClient\Exceptions\InvalidFormatException;
77use Meema\MeemaClient\Response\Response;
88use Meema\MeemaClient\Traits\CollectionsResponse;
9use Meema\MeemaClient\Traits\ValidsUuid;
910
1011class Media
1112{
12 use CollectionsResponse;
13 use CollectionsResponse, ValidsUuid;
1314
1415 /**
1516 * @var \Meema\MeemaClient\Client
@@ -68,8 +69,8 @@ class Media
6869 $ids = is_array($ids) ? $ids : func_get_args();
6970
7071 foreach ($ids as $id) {
71 if (! is_int($id)) {
72 throw new InvalidFormatException();
72 if (! $this->isValidUuid($id)) {
73 throw new InvalidFormatException('ID is not a valid UUID');
7374 }
7475 }
7576
@@ -103,8 +104,8 @@ class Media
103104 */
104105 public function find($id)
105106 {
106 if (! is_int($id)) {
107 throw new InvalidFormatException();
107 if (! $this->isValidUuid($id)) {
108 throw new InvalidFormatException('ID is not a valid UUID');
108109 }
109110
110111 $response = $this->client->request('GET', "media/${id}");
@@ -138,8 +139,8 @@ class Media
138139 */
139140 public function update($id, $name)
140141 {
141 if (! is_int($id)) {
142 throw new InvalidFormatException();
142 if (! $this->isValidUuid($id)) {
143 throw new InvalidFormatException('ID is not a valid UUID');
143144 }
144145
145146 $name = is_array($name) ? $name : compact('name');
@@ -161,8 +162,8 @@ class Media
161162 $ids = is_array($ids) ? $ids : func_get_args();
162163
163164 foreach ($ids as $id) {
164 if (! is_int($id)) {
165 throw new InvalidFormatException();
165 if (! $this->isValidUuid($id)) {
166 throw new InvalidFormatException('ID is not a valid UUID');
166167 }
167168 }
168169
@@ -190,8 +191,8 @@ class Media
190191 $ids = is_array($ids) ? $ids : func_get_args();
191192
192193 foreach ($ids as $id) {
193 if (! is_int($id)) {
194 throw new InvalidFormatException();
194 if (! $this->isValidUuid($id)) {
195 throw new InvalidFormatException('ID is not a valid UUID');
195196 }
196197 }
197198
@@ -219,8 +220,8 @@ class Media
219220 $ids = is_array($ids) ? $ids : func_get_args();
220221
221222 foreach ($ids as $id) {
222 if (! is_int($id)) {
223 throw new InvalidFormatException();
223 if (! $this->isValidUuid($id)) {
224 throw new InvalidFormatException('ID is not a valid UUID');
224225 }
225226 }
226227
@@ -248,8 +249,8 @@ class Media
248249 $ids = is_array($ids) ? $ids : func_get_args();
249250
250251 foreach ($ids as $id) {
251 if (! is_int($id)) {
252 throw new InvalidFormatException();
252 if (! $this->isValidUuid($id)) {
253 throw new InvalidFormatException('ID is not a valid UUID');
253254 }
254255 }
255256
@@ -277,8 +278,8 @@ class Media
277278 $ids = is_array($ids) ? $ids : func_get_args();
278279
279280 foreach ($ids as $id) {
280 if (! is_int($id)) {
281 throw new InvalidFormatException();
281 if (! $this->isValidUuid($id)) {
282 throw new InvalidFormatException('ID is not a valid UUID');
282283 }
283284 }
284285
@@ -306,8 +307,8 @@ class Media
306307 $ids = is_array($ids) ? $ids : func_get_args();
307308
308309 foreach ($ids as $id) {
309 if (! is_int($id)) {
310 throw new InvalidFormatException();
310 if (! $this->isValidUuid($id)) {
311 throw new InvalidFormatException('ID is not a valid UUID');
311312 }
312313 }
313314