also looking at this
Tags model
#14
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.
| @@ -15,7 +15,7 @@ class Folder | ||
| 15 | 15 | /** |
| 16 | 16 | * @var int |
| 17 | 17 | */ |
| 18 | public $id; | |
| 18 | protected $id; | |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var object |
| @@ -71,8 +71,6 @@ class Folder | ||
| 71 | 71 | { |
| 72 | 72 | $response = $this->client->request('GET', "folders/${id}"); |
| 73 | 73 | |
| 74 | $this->id = $response['data']['id']; | |
| 75 | ||
| 76 | 74 | return new Response($this, $response); |
| 77 | 75 | } |
| 78 | 76 | |
| @@ -202,6 +200,20 @@ class Folder | ||
| 202 | 200 | return $this; |
| 203 | 201 | } |
| 204 | 202 | |
| 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 | ||
| 205 | 217 | /** |
| 206 | 218 | * Get the protected id. |
| 207 | 219 | * |
| @@ -229,11 +241,11 @@ class Folder | ||
| 229 | 241 | * |
| 230 | 242 | * @return Meema\MeemaApi\Models\Tag |
| 231 | 243 | */ |
| 232 | public function tags(): Tag | |
| 244 | public function tags($id = null): Tag | |
| 233 | 245 | { |
| 234 | $client = new Client($this->client->getAccessKey()); | |
| 246 | $this->id = $id; | |
| 235 | 247 | |
| 236 | return (new Tag($client))->setFolder($this); | |
| 248 | return (new Tag($this->client))->setFolder($this); | |
| 237 | 249 | } |
| 238 | 250 | |
| 239 | 251 | /** |
| @@ -194,11 +194,11 @@ class Media | ||
| 194 | 194 | * |
| 195 | 195 | * @return Meema\MeemaApi\Models\Tag |
| 196 | 196 | */ |
| 197 | public function tags(): Tag | |
| 197 | public function tags($id = null): Tag | |
| 198 | 198 | { |
| 199 | $client = new Client($this->client->getAccessKey()); | |
| 199 | $this->id = $id; | |
| 200 | 200 | |
| 201 | return (new Tag($client))->setMedia($this); | |
| 201 | return (new Tag($this->client))->setMedia($this); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
| @@ -8,14 +8,14 @@ use Meema\MeemaApi\Response\Response; | ||
| 8 | 8 | class Tag |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | * @var Meema\MeemaApi\Client | |
| 11 | * @var \Meema\MeemaApi\Client | |
| 12 | 12 | */ |
| 13 | 13 | protected $client; |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * @var int |
| 17 | 17 | */ |
| 18 | public $id; | |
| 18 | protected $id; | |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var object |
| @@ -49,7 +49,7 @@ class Tag | ||
| 49 | 49 | * |
| 50 | 50 | * @return array |
| 51 | 51 | */ |
| 52 | public function get($id = null) | |
| 52 | public function get($id = null): array | |
| 53 | 53 | { |
| 54 | 54 | if ($this->model) { |
| 55 | 55 | return $this->fetchForModel(); |
| @@ -69,25 +69,23 @@ class Tag | ||
| 69 | 69 | * |
| 70 | 70 | * @param int $id |
| 71 | 71 | * |
| 72 | * @return array | |
| 72 | * @return Response | |
| 73 | 73 | */ |
| 74 | public function find($id) | |
| 74 | public function find($id): Response | |
| 75 | 75 | { |
| 76 | 76 | $response = $this->client->request('GET', "tags/${id}"); |
| 77 | 77 | |
| 78 | $this->id = $response['data']['id']; | |
| 79 | ||
| 80 | 78 | return new Response($this, $response); |
| 81 | 79 | } |
| 82 | 80 | |
| 83 | 81 | /** |
| 84 | 82 | * Create folder. |
| 85 | 83 | * |
| 86 | * @param string $name | |
| 84 | * @param string $name | |
| 87 | 85 | * |
| 88 | 86 | * @return array |
| 89 | 87 | */ |
| 90 | public function create($name) | |
| 88 | public function create($name): array | |
| 91 | 89 | { |
| 92 | 90 | $name = is_array($name) ? $name : compact('name'); |
| 93 | 91 | |
| @@ -112,7 +110,7 @@ class Tag | ||
| 112 | 110 | * |
| 113 | 111 | * @param int $id |
| 114 | 112 | * |
| 115 | * @return null | |
| 113 | * @return Response | |
| 116 | 114 | */ |
| 117 | 115 | public function delete($id) |
| 118 | 116 | { |
| @@ -124,11 +122,11 @@ class Tag | ||
| 124 | 122 | * |
| 125 | 123 | * @return Meema\MeemaApi\Models\Media |
| 126 | 124 | */ |
| 127 | public function media(): Media | |
| 125 | public function media($id = null): Media | |
| 128 | 126 | { |
| 129 | $client = new Client($this->client->getAccessKey()); | |
| 127 | $this->id = $id; | |
| 130 | 128 | |
| 131 | return (new Media($client))->setTag($this); | |
| 129 | return (new Media($this->client))->setTag($this); | |
| 132 | 130 | } |
| 133 | 131 | |
| 134 | 132 | /** |
| @@ -136,11 +134,11 @@ class Tag | ||
| 136 | 134 | * |
| 137 | 135 | * @return Meema\MeemaApi\Models\Folder |
| 138 | 136 | */ |
| 139 | public function folders(): Folder | |
| 137 | public function folders($id = null): Folder | |
| 140 | 138 | { |
| 141 | $client = new Client($this->client->getAccessKey()); | |
| 139 | $this->id = $id; | |
| 142 | 140 | |
| 143 | return new Folder($client, $this); | |
| 141 | return (new Folder($this->client))->setTag($this); | |
| 144 | 142 | } |
| 145 | 143 | |
| 146 | 144 | /** |
| @@ -195,6 +193,16 @@ class Tag | ||
| 195 | 193 | return $this; |
| 196 | 194 | } |
| 197 | 195 | |
| 196 | /** | |
| 197 | * Get the protected id. | |
| 198 | * | |
| 199 | * @return int | |
| 200 | */ | |
| 201 | public function getId() | |
| 202 | { | |
| 203 | return $this->id; | |
| 204 | } | |
| 205 | ||
| 198 | 206 | /** |
| 199 | 207 | * Fetch child relations for this instance. |
| 200 | 208 | * |
| @@ -45,7 +45,7 @@ class Response | ||
| 45 | 45 | * |
| 46 | 46 | * @return string |
| 47 | 47 | */ |
| 48 | public function getKeyName() | |
| 48 | public function getKeyName(): string | |
| 49 | 49 | { |
| 50 | 50 | return 'id'; |
| 51 | 51 | } |
| @@ -74,6 +74,7 @@ class Response | ||
| 74 | 74 | * Get response content. |
| 75 | 75 | * |
| 76 | 76 | * @param mixed $key |
| 77 | * | |
| 77 | 78 | * @return array |
| 78 | 79 | */ |
| 79 | 80 | public function getContent($key = null) |