ReviewOS

also looking at this

meemalabs/meema-client-php

Favorites model

#11
Merged glennmichael123 wants to merge tags-model into main
3 files +131 -0

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/Favorite.phpmodified+3-25
Changes to src/Models/Favorite.php
@@ -4,12 +4,9 @@ namespace Meema\MeemaApi\Models;
44
55use Meema\MeemaApi\Client;
66use Meema\MeemaApi\Response\Response;
7use Meema\MeemaApi\Traits\SerializesResponse;
87
98class Favorite
109{
11 use SerializesResponse;
12
1310 /**
1411 * @var Meema\MeemaApi\Client
1512 */
@@ -20,26 +17,14 @@ class Favorite
2017 */
2118 protected $id;
2219
23 /**
24 * @var int
25 */
26 protected $favoriteId;
27
28 /**
29 * @var array
30 */
31 protected $content;
32
3320 /**
3421 * Construct Favorite model.
3522 *
3623 * @param Meema\MeemaApi\Client $client
3724 */
38 public function __construct(Client $client, $favoriteId = null)
25 public function __construct(Client $client)
3926 {
4027 $this->client = $client;
41
42 $this->favoriteId = $favoriteId;
4328 }
4429
4530 /**
@@ -81,9 +66,6 @@ class Favorite
8166 {
8267 $response = $this->client->request('GET', "favorites/${id}");
8368
84 $this->content = $response;
85 $this->id = $response['data']['id'];
86
8769 return new Response($this, $response);
8870 }
8971
@@ -107,10 +89,8 @@ class Favorite
10789 *
10890 * @return array
10991 */
110 public function update($data, $id = null): array
92 public function update($id, $data): array
11193 {
112 $id = $this->id ?? $id;
113
11494 return $this->client->request('PATCH', "favorites/{$id}", $data);
11595 }
11696
@@ -121,10 +101,8 @@ class Favorite
121101 *
122102 * @return null
123103 */
124 public function delete($id = null)
104 public function delete($id)
125105 {
126 $id = $this->id ?? $id;
127
128106 return $this->client->request('DELETE', "favorites/{$id}");
129107 }
130108}
src/Response/Response.phpmodified+12-0
Changes to src/Response/Response.php
@@ -85,4 +85,16 @@ class Response
8585
8686 return $this->content;
8787 }
88
89 /**
90 * Get response content to array.
91 *
92 * @param mixed $key
93 *
94 * @return array
95 */
96 public function toArray()
97 {
98 return $this->getContent();
99 }
88100}