ReviewOS

also looking at this

meemalabs/meema-client-php

Collection response

#52
Merged glennmichael123 wants to merge collection-response into main
11 files +3638 -3582
src/Models/Folder.phpmodified+16-9
Changes to src/Models/Folder.php
@@ -5,9 +5,12 @@ namespace Meema\MeemaApi\Models;
55use Meema\MeemaApi\Client;
66use Meema\MeemaApi\Exceptions\InvalidFormatException;
77use Meema\MeemaApi\Response\Response;
8use Meema\MeemaApi\Traits\CollectionsResponse;
89
910class Folder
1011{
12 use CollectionsResponse;
13
1114 /**
1215 * @var \Meema\MeemaApi\Client
1316 */
@@ -38,7 +41,7 @@ class Folder
3841 *
3942 * @return array
4043 */
41 public function all(): array
44 public function all()
4245 {
4346 return $this->client->request('GET', 'folders');
4447 }
@@ -48,14 +51,14 @@ class Folder
4851 *
4952 * @param int $id
5053 *
51 * @return mixed
54 * @return \Illuminate\Support\Collection|array
5255 *
5356 * @throws InvalidFormatException
5457 */
5558 public function get($id = null)
5659 {
5760 if (! $id) {
58 return $this->all();
61 return $this->toCollection($this->all());
5962 }
6063
6164 $ids = is_array($id) ? $id : func_get_args();
@@ -66,7 +69,9 @@ class Folder
6669 }
6770 }
6871
69 return $this->client->request('GET', 'folders', ['folder_ids' => $ids]);
72 $response = $this->client->request('GET', 'folders', ['folder_ids' => $ids]);
73
74 return $this->toCollection($response);
7075 }
7176
7277 /**
@@ -78,7 +83,9 @@ class Folder
7883 */
7984 public function search($query)
8085 {
81 return $this->client->request('POST', 'folders/search', compact('query'));
86 $response = $this->client->request('POST', 'folders/search', compact('query'));
87
88 return $this->toCollection($response);
8289 }
8390
8491 /**
@@ -108,7 +115,7 @@ class Folder
108115 *
109116 * @return array
110117 */
111 public function create($name): array
118 public function create($name)
112119 {
113120 $name = is_array($name) ? $name : compact('name');
114121
@@ -129,7 +136,7 @@ class Folder
129136 *
130137 * @return array
131138 */
132 public function update($id, $name): array
139 public function update($id, $name)
133140 {
134141 if (! is_int($id)) {
135142 throw new InvalidFormatException();
@@ -240,7 +247,7 @@ class Folder
240247 *
241248 * @throws InvalidFormatException
242249 */
243 public function duplicate($ids): array
250 public function duplicate($ids)
244251 {
245252 $ids = is_array($ids) ? $ids : func_get_args();
246253
@@ -270,7 +277,7 @@ class Folder
270277 *
271278 * @throws InvalidFormatException
272279 */
273 protected function addFolderToMedia($id, $name): array
280 protected function addFolderToMedia($id, $name)
274281 {
275282 if (! is_int($id)) {
276283 throw new InvalidFormatException();