ReviewOS

also looking at this

meemalabs/meema-client-php

Media model

#6
Merged glennmichael123 wants to merge media-model into main
7 files +1700 -76

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/Folder.phpmodified+13-31
Changes to src/Models/Folder.php
@@ -8,7 +8,7 @@ use Meema\MeemaApi\Response\Response;
88class Folder
99{
1010 /**
11 * @var Meema\MeemaApi\Client
11 * @var \Meema\MeemaApi\Client
1212 */
1313 protected $client;
1414
@@ -22,11 +22,6 @@ class Folder
2222 */
2323 protected $model;
2424
25 /**
26 * @var array
27 */
28 protected $content;
29
3025 /**
3126 * Construct Folder model.
3227 *
@@ -70,13 +65,12 @@ class Folder
7065 *
7166 * @param int $id
7267 *
73 * @return array
68 * @return Response
7469 */
75 public function find($id)
70 public function find($id): Response
7671 {
7772 $response = $this->client->request('GET', "folders/${id}");
7873
79 $this->content = $response;
8074 $this->id = $response['data']['id'];
8175
8276 return new Response($this, $response);
@@ -89,7 +83,7 @@ class Folder
8983 *
9084 * @return array
9185 */
92 public function create($name)
86 public function create($name): array
9387 {
9488 $name = is_array($name) ? $name : compact('name');
9589
@@ -110,10 +104,8 @@ class Folder
110104 *
111105 * @return array
112106 */
113 public function update($name, $id = null): array
107 public function update($id, $name): array
114108 {
115 $id = $this->id ?? $id;
116
117109 $name = is_array($name) ? $name : compact('name');
118110
119111 return $this->client->request('PATCH', "folders/{$id}", $name);
@@ -126,14 +118,12 @@ class Folder
126118 *
127119 * @return null
128120 */
129 public function delete($id = null)
121 public function delete($id)
130122 {
131123 if ($this->model) {
132124 return $this->deleteFolderFromMedia($this->model->getId(), $id);
133125 }
134126
135 $id = $this->id ?? $id;
136
137127 return $this->client->request('DELETE', "folders/{$id}");
138128 }
139129
@@ -144,10 +134,8 @@ class Folder
144134 *
145135 * @return array
146136 */
147 public function archive($id = null): array
137 public function archive($id): array
148138 {
149 $id = $this->id ?? $id;
150
151139 return $this->client->request('POST', "folders/{$id}/archive");
152140 }
153141
@@ -158,10 +146,8 @@ class Folder
158146 *
159147 * @return array
160148 */
161 public function unarchive($id = null): array
149 public function unarchive($id): array
162150 {
163 $id = $this->id ?? $id;
164
165151 return $this->client->request('POST', "folders/{$id}/unarchive");
166152 }
167153
@@ -172,10 +158,8 @@ class Folder
172158 *
173159 * @return array
174160 */
175 public function duplicate($id = null): array
161 public function duplicate($id): array
176162 {
177 $id = $this->id ?? $id;
178
179163 return $this->client->request('POST', "folders/{$id}/duplicate");
180164 }
181165
@@ -186,7 +170,7 @@ class Folder
186170 *
187171 * @return array
188172 */
189 public function addFolderToMedia($id, $name)
173 public function addFolderToMedia($id, $name): array
190174 {
191175 return $this->client->request('POST', "media/{$id}/folders", $name);
192176 }
@@ -196,7 +180,7 @@ class Folder
196180 *
197181 * @param int $id
198182 *
199 * @return array
183 * @return null
200184 */
201185 public function deleteFolderFromMedia($mediaId, $folderId)
202186 {
@@ -222,7 +206,7 @@ class Folder
222206 *
223207 * @return int
224208 */
225 public function getId()
209 public function getId(): int
226210 {
227211 return $this->id;
228212 }
@@ -234,8 +218,6 @@ class Folder
234218 */
235219 public function media(): Media
236220 {
237 $client = new Client($this->client->getAccessKey());
238
239 return (new Media($client))->setFolder($this);
221 return (new Media($this->client))->setFolder($this);
240222 }
241223}
src/Models/Media.phpmodified+4-11
Changes to src/Models/Media.php
@@ -8,7 +8,7 @@ use Meema\MeemaApi\Response\Response;
88class Media
99{
1010 /**
11 * @var Meema\MeemaApi\Client
11 * @var \Meema\MeemaApi\Client
1212 */
1313 protected $client;
1414
@@ -22,11 +22,6 @@ class Media
2222 */
2323 protected $model;
2424
25 /**
26 * @var array
27 */
28 protected $content;
29
3025 /**
3126 * Construct media model.
3227 *
@@ -78,8 +73,6 @@ class Media
7873 {
7974 $response = $this->client->request('GET', "folders/${id}");
8075
81 $this->id = $response['data']['id'];
82
8376 return new Response($this, $response);
8477 }
8578
@@ -189,11 +182,11 @@ class Media
189182 *
190183 * @return Meema\MeemaApi\Models\Folder
191184 */
192 public function folders()
185 public function folders($id = null)
193186 {
194 $client = new Client($this->client->getAccessKey());
187 $this->id = $id;
195188
196 return (new Folder($client))->setMedia($this);
189 return (new Folder($this->client))->setMedia($this);
197190 }
198191
199192 /**
src/Traits/SerializesResponse.phpdeleted+0-16
Changes to src/Traits/SerializesResponse.php
@@ -1,16 +0,0 @@
1<?php
2
3namespace Meema\MeemaApi\Traits;
4
5trait SerializesResponse
6{
7 /**
8 * Convert the response to array.
9 *
10 * @return array
11 */
12 public function toArray()
13 {
14 return $this->content;
15 }
16}