also looking at this
Media model
#6
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.
| @@ -8,7 +8,7 @@ use Meema\MeemaApi\Response\Response; | ||
| 8 | 8 | class Folder |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | * @var Meema\MeemaApi\Client | |
| 11 | * @var \Meema\MeemaApi\Client | |
| 12 | 12 | */ |
| 13 | 13 | protected $client; |
| 14 | 14 | |
| @@ -22,11 +22,6 @@ class Folder | ||
| 22 | 22 | */ |
| 23 | 23 | protected $model; |
| 24 | 24 | |
| 25 | /** | |
| 26 | * @var array | |
| 27 | */ | |
| 28 | protected $content; | |
| 29 | ||
| 30 | 25 | /** |
| 31 | 26 | * Construct Folder model. |
| 32 | 27 | * |
| @@ -70,13 +65,12 @@ class Folder | ||
| 70 | 65 | * |
| 71 | 66 | * @param int $id |
| 72 | 67 | * |
| 73 | * @return array | |
| 68 | * @return Response | |
| 74 | 69 | */ |
| 75 | public function find($id) | |
| 70 | public function find($id): Response | |
| 76 | 71 | { |
| 77 | 72 | $response = $this->client->request('GET', "folders/${id}"); |
| 78 | 73 | |
| 79 | $this->content = $response; | |
| 80 | 74 | $this->id = $response['data']['id']; |
| 81 | 75 | |
| 82 | 76 | return new Response($this, $response); |
| @@ -89,7 +83,7 @@ class Folder | ||
| 89 | 83 | * |
| 90 | 84 | * @return array |
| 91 | 85 | */ |
| 92 | public function create($name) | |
| 86 | public function create($name): array | |
| 93 | 87 | { |
| 94 | 88 | $name = is_array($name) ? $name : compact('name'); |
| 95 | 89 | |
| @@ -110,10 +104,8 @@ class Folder | ||
| 110 | 104 | * |
| 111 | 105 | * @return array |
| 112 | 106 | */ |
| 113 | public function update($name, $id = null): array | |
| 107 | public function update($id, $name): array | |
| 114 | 108 | { |
| 115 | $id = $this->id ?? $id; | |
| 116 | ||
| 117 | 109 | $name = is_array($name) ? $name : compact('name'); |
| 118 | 110 | |
| 119 | 111 | return $this->client->request('PATCH', "folders/{$id}", $name); |
| @@ -126,14 +118,12 @@ class Folder | ||
| 126 | 118 | * |
| 127 | 119 | * @return null |
| 128 | 120 | */ |
| 129 | public function delete($id = null) | |
| 121 | public function delete($id) | |
| 130 | 122 | { |
| 131 | 123 | if ($this->model) { |
| 132 | 124 | return $this->deleteFolderFromMedia($this->model->getId(), $id); |
| 133 | 125 | } |
| 134 | 126 | |
| 135 | $id = $this->id ?? $id; | |
| 136 | ||
| 137 | 127 | return $this->client->request('DELETE', "folders/{$id}"); |
| 138 | 128 | } |
| 139 | 129 | |
| @@ -144,10 +134,8 @@ class Folder | ||
| 144 | 134 | * |
| 145 | 135 | * @return array |
| 146 | 136 | */ |
| 147 | public function archive($id = null): array | |
| 137 | public function archive($id): array | |
| 148 | 138 | { |
| 149 | $id = $this->id ?? $id; | |
| 150 | ||
| 151 | 139 | return $this->client->request('POST', "folders/{$id}/archive"); |
| 152 | 140 | } |
| 153 | 141 | |
| @@ -158,10 +146,8 @@ class Folder | ||
| 158 | 146 | * |
| 159 | 147 | * @return array |
| 160 | 148 | */ |
| 161 | public function unarchive($id = null): array | |
| 149 | public function unarchive($id): array | |
| 162 | 150 | { |
| 163 | $id = $this->id ?? $id; | |
| 164 | ||
| 165 | 151 | return $this->client->request('POST', "folders/{$id}/unarchive"); |
| 166 | 152 | } |
| 167 | 153 | |
| @@ -172,10 +158,8 @@ class Folder | ||
| 172 | 158 | * |
| 173 | 159 | * @return array |
| 174 | 160 | */ |
| 175 | public function duplicate($id = null): array | |
| 161 | public function duplicate($id): array | |
| 176 | 162 | { |
| 177 | $id = $this->id ?? $id; | |
| 178 | ||
| 179 | 163 | return $this->client->request('POST', "folders/{$id}/duplicate"); |
| 180 | 164 | } |
| 181 | 165 | |
| @@ -186,7 +170,7 @@ class Folder | ||
| 186 | 170 | * |
| 187 | 171 | * @return array |
| 188 | 172 | */ |
| 189 | public function addFolderToMedia($id, $name) | |
| 173 | public function addFolderToMedia($id, $name): array | |
| 190 | 174 | { |
| 191 | 175 | return $this->client->request('POST', "media/{$id}/folders", $name); |
| 192 | 176 | } |
| @@ -196,7 +180,7 @@ class Folder | ||
| 196 | 180 | * |
| 197 | 181 | * @param int $id |
| 198 | 182 | * |
| 199 | * @return array | |
| 183 | * @return null | |
| 200 | 184 | */ |
| 201 | 185 | public function deleteFolderFromMedia($mediaId, $folderId) |
| 202 | 186 | { |
| @@ -222,7 +206,7 @@ class Folder | ||
| 222 | 206 | * |
| 223 | 207 | * @return int |
| 224 | 208 | */ |
| 225 | public function getId() | |
| 209 | public function getId(): int | |
| 226 | 210 | { |
| 227 | 211 | return $this->id; |
| 228 | 212 | } |
| @@ -234,8 +218,6 @@ class Folder | ||
| 234 | 218 | */ |
| 235 | 219 | public function media(): Media |
| 236 | 220 | { |
| 237 | $client = new Client($this->client->getAccessKey()); | |
| 238 | ||
| 239 | return (new Media($client))->setFolder($this); | |
| 221 | return (new Media($this->client))->setFolder($this); | |
| 240 | 222 | } |
| 241 | 223 | } |
| @@ -8,7 +8,7 @@ use Meema\MeemaApi\Response\Response; | ||
| 8 | 8 | class Media |
| 9 | 9 | { |
| 10 | 10 | /** |
| 11 | * @var Meema\MeemaApi\Client | |
| 11 | * @var \Meema\MeemaApi\Client | |
| 12 | 12 | */ |
| 13 | 13 | protected $client; |
| 14 | 14 | |
| @@ -22,11 +22,6 @@ class Media | ||
| 22 | 22 | */ |
| 23 | 23 | protected $model; |
| 24 | 24 | |
| 25 | /** | |
| 26 | * @var array | |
| 27 | */ | |
| 28 | protected $content; | |
| 29 | ||
| 30 | 25 | /** |
| 31 | 26 | * Construct media model. |
| 32 | 27 | * |
| @@ -78,8 +73,6 @@ class Media | ||
| 78 | 73 | { |
| 79 | 74 | $response = $this->client->request('GET', "folders/${id}"); |
| 80 | 75 | |
| 81 | $this->id = $response['data']['id']; | |
| 82 | ||
| 83 | 76 | return new Response($this, $response); |
| 84 | 77 | } |
| 85 | 78 | |
| @@ -189,11 +182,11 @@ class Media | ||
| 189 | 182 | * |
| 190 | 183 | * @return Meema\MeemaApi\Models\Folder |
| 191 | 184 | */ |
| 192 | public function folders() | |
| 185 | public function folders($id = null) | |
| 193 | 186 | { |
| 194 | $client = new Client($this->client->getAccessKey()); | |
| 187 | $this->id = $id; | |
| 195 | 188 | |
| 196 | return (new Folder($client))->setMedia($this); | |
| 189 | return (new Folder($this->client))->setMedia($this); | |
| 197 | 190 | } |
| 198 | 191 | |
| 199 | 192 | /** |