ReviewOS

also looking at this

meemalabs/meema-client-php

Tags model

#14
Merged glennmichael123 wants to merge tags-model-2 into main
5 files +165 -74

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+12-0
Changes to src/Models/Folder.php
@@ -235,4 +235,16 @@ class Folder
235235
236236 return (new Tag($client))->setFolder($this);
237237 }
238
239 /**
240 * Initialize the tags model.
241 *
242 * @return Meema\MeemaApi\Models\Tag
243 */
244 public function tags(): Tag
245 {
246 $client = new Client($this->client->getAccessKey());
247
248 return (new Tag($client))->setFolder($this);
249 }
238250}
src/Models/Media.phpmodified+3-2
Changes to src/Models/Media.php
@@ -189,10 +189,11 @@ class Media
189189 return (new Folder($this->client))->setMedia($this);
190190 }
191191
192
192193 /**
193 * Initialize media model.
194 * Fetch the media for the folder.
194195 *
195 * @param Meema\MeemaApi\Models\Folder $folder
196 * @param int $id
196197 *
197198 * @return self
198199 */
src/Models/Tag.phpmodified+23-7
Changes to src/Models/Tag.php
@@ -119,8 +119,6 @@ class Tag
119119 */
120120 public function delete($id)
121121 {
122 $id = $this->id ?? $id;
123
124122 return $this->client->request('DELETE', "tags/{$id}");
125123 }
126124
@@ -133,7 +131,7 @@ class Tag
133131 {
134132 $client = new Client($this->client->getAccessKey());
135133
136 return new Media($client, $this);
134 return (new Media($client))->setTag($this);
137135 }
138136
139137 /**
@@ -186,6 +184,20 @@ class Tag
186184 return $this;
187185 }
188186
187 /**
188 * Initialize media model.
189 *
190 * @param Meema\MeemaApi\Models\Media $media
191 *
192 * @return self
193 */
194 public function setMedia($media): self
195 {
196 $this->model = $media;
197
198 return $this;
199 }
200
189201 /**
190202 * Fetch child relations for this instance.
191203 *
@@ -193,15 +205,19 @@ class Tag
193205 */
194206 public function fetchForModel(): array
195207 {
208 $data = [];
209
196210 switch (get_class($this->model)) {
197211 case Folder::class:
198 return $this->fetchTagsForFolder($this->model->id);
212 $data = $this->fetchTagsForFolder($this->model->getId());
213 break;
199214 case Media::class:
200 return $this->fetchTagsForMedia($this->model->id);
215 $data = $this->fetchTagsForMedia($this->model->getId());
216 break;
201217 default:
202 return [];
218 $data = [];
203219 }
204220
205 return [];
221 return $data;
206222 }
207223}