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+18-6
Changes to src/Models/Folder.php
@@ -15,7 +15,7 @@ class Folder
1515 /**
1616 * @var int
1717 */
18 public $id;
18 protected $id;
1919
2020 /**
2121 * @var object
@@ -71,8 +71,6 @@ class Folder
7171 {
7272 $response = $this->client->request('GET', "folders/${id}");
7373
74 $this->id = $response['data']['id'];
75
7674 return new Response($this, $response);
7775 }
7876
@@ -202,6 +200,20 @@ class Folder
202200 return $this;
203201 }
204202
203 /**
204 * Initialize media model.
205 *
206 * @param Meema\MeemaApi\Models\Folder $folder
207 *
208 * @return self
209 */
210 public function setTag($tag): self
211 {
212 $this->model = $tag;
213
214 return $this;
215 }
216
205217 /**
206218 * Get the protected id.
207219 *
@@ -229,11 +241,11 @@ class Folder
229241 *
230242 * @return Meema\MeemaApi\Models\Tag
231243 */
232 public function tags(): Tag
244 public function tags($id = null): Tag
233245 {
234 $client = new Client($this->client->getAccessKey());
246 $this->id = $id;
235247
236 return (new Tag($client))->setFolder($this);
248 return (new Tag($this->client))->setFolder($this);
237249 }
238250
239251 /**
src/Models/Media.phpmodified+3-3
Changes to src/Models/Media.php
@@ -194,11 +194,11 @@ class Media
194194 *
195195 * @return Meema\MeemaApi\Models\Tag
196196 */
197 public function tags(): Tag
197 public function tags($id = null): Tag
198198 {
199 $client = new Client($this->client->getAccessKey());
199 $this->id = $id;
200200
201 return (new Tag($client))->setMedia($this);
201 return (new Tag($this->client))->setMedia($this);
202202 }
203203
204204 /**
src/Models/Tag.phpmodified+24-16
Changes to src/Models/Tag.php
@@ -8,14 +8,14 @@ use Meema\MeemaApi\Response\Response;
88class Tag
99{
1010 /**
11 * @var Meema\MeemaApi\Client
11 * @var \Meema\MeemaApi\Client
1212 */
1313 protected $client;
1414
1515 /**
1616 * @var int
1717 */
18 public $id;
18 protected $id;
1919
2020 /**
2121 * @var object
@@ -49,7 +49,7 @@ class Tag
4949 *
5050 * @return array
5151 */
52 public function get($id = null)
52 public function get($id = null): array
5353 {
5454 if ($this->model) {
5555 return $this->fetchForModel();
@@ -69,25 +69,23 @@ class Tag
6969 *
7070 * @param int $id
7171 *
72 * @return array
72 * @return Response
7373 */
74 public function find($id)
74 public function find($id): Response
7575 {
7676 $response = $this->client->request('GET', "tags/${id}");
7777
78 $this->id = $response['data']['id'];
79
8078 return new Response($this, $response);
8179 }
8280
8381 /**
8482 * Create folder.
8583 *
86 * @param string $name
84 * @param string $name
8785 *
8886 * @return array
8987 */
90 public function create($name)
88 public function create($name): array
9189 {
9290 $name = is_array($name) ? $name : compact('name');
9391
@@ -112,7 +110,7 @@ class Tag
112110 *
113111 * @param int $id
114112 *
115 * @return null
113 * @return Response
116114 */
117115 public function delete($id)
118116 {
@@ -124,11 +122,11 @@ class Tag
124122 *
125123 * @return Meema\MeemaApi\Models\Media
126124 */
127 public function media(): Media
125 public function media($id = null): Media
128126 {
129 $client = new Client($this->client->getAccessKey());
127 $this->id = $id;
130128
131 return (new Media($client))->setTag($this);
129 return (new Media($this->client))->setTag($this);
132130 }
133131
134132 /**
@@ -136,11 +134,11 @@ class Tag
136134 *
137135 * @return Meema\MeemaApi\Models\Folder
138136 */
139 public function folders(): Folder
137 public function folders($id = null): Folder
140138 {
141 $client = new Client($this->client->getAccessKey());
139 $this->id = $id;
142140
143 return new Folder($client, $this);
141 return (new Folder($this->client))->setTag($this);
144142 }
145143
146144 /**
@@ -195,6 +193,16 @@ class Tag
195193 return $this;
196194 }
197195
196 /**
197 * Get the protected id.
198 *
199 * @return int
200 */
201 public function getId()
202 {
203 return $this->id;
204 }
205
198206 /**
199207 * Fetch child relations for this instance.
200208 *
src/Response/Response.phpmodified+2-1
Changes to src/Response/Response.php
@@ -45,7 +45,7 @@ class Response
4545 *
4646 * @return string
4747 */
48 public function getKeyName()
48 public function getKeyName(): string
4949 {
5050 return 'id';
5151 }
@@ -74,6 +74,7 @@ class Response
7474 * Get response content.
7575 *
7676 * @param mixed $key
77 *
7778 * @return array
7879 */
7980 public function getContent($key = null)