This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Baguette\Mastodon; |
||
4 | |||
5 | use Baguette\Mastodon\Client; |
||
6 | use Baguette\Mastodon\Entity; |
||
7 | use Baguette\Mastodon\Service\SessionStorage; |
||
8 | use Baguette\Mastodon\Service\Toot; |
||
9 | use Psr\Http\Message\ResponseInterface; |
||
10 | use Respect\Validation\Validator as v; |
||
11 | |||
12 | /** |
||
13 | * Mastodon Anthorization object factory |
||
14 | * |
||
15 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md |
||
16 | * @author USAMI Kenta <[email protected]> |
||
17 | * @copyright 2017 Baguette HQ |
||
18 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0 |
||
19 | */ |
||
20 | class Requester |
||
21 | { |
||
22 | // |
||
23 | // Account API |
||
24 | // |
||
25 | |||
26 | /** |
||
27 | * Fetching an account |
||
28 | * |
||
29 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#fetching-an-account |
||
30 | * @param Client $client |
||
31 | * @param SessionStorage $session |
||
32 | * @param int $id |
||
33 | * @return Entity\Account |
||
34 | */ |
||
35 | 1 | View Code Duplication | public static function getAccount(Client $client, SessionStorage $session, $id) |
0 ignored issues
–
show
|
|||
36 | { |
||
37 | 1 | v::intVal()->min(0)->assert($id); |
|
38 | |||
39 | 1 | return static::map( |
|
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
40 | 1 | Entity\Account::class, |
|
41 | 1 | $client->requestAPI('GET', sprintf('/api/v1/accounts/%d', $id), [], $session) |
|
42 | ); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Getting the current user |
||
47 | * |
||
48 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#getting-the-current-user |
||
49 | * @param Client $client |
||
50 | * @param SessionStorage $session |
||
51 | * @return Entity\Account |
||
52 | */ |
||
53 | public static function getAccountCurrentUser(Client $client, SessionStorage $session) |
||
54 | { |
||
55 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() The expression
static::map(\Baguette\Ma...', array(), $session)); of type object|array adds the type array to the return on line 55 which is incompatible with the return type documented by Baguette\Mastodon\Requester::getAccountCurrentUser of type Baguette\Mastodon\Entity\Account .
![]() |
|||
56 | Entity\Account::class, |
||
57 | $client->requestAPI('GET', '/api/v1/accounts/verify_credentials', [], $session) |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Updating the current user |
||
63 | * |
||
64 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#updating-the-current-user |
||
65 | * @param Client $client |
||
66 | * @param SessionStorage $session |
||
67 | * @param array $update_data |
||
68 | * @return Entity\Account |
||
69 | */ |
||
70 | public static function updateAccount(Client $client, SessionStorage $session, $update_data) |
||
71 | { |
||
72 | $form_params = []; |
||
73 | |||
74 | if (isset($update_data['display_name'])) { |
||
75 | v::stringType()->assert($update_data['display_name']); |
||
76 | $form_params['display_name'] = (string)$update_data['display_name']; |
||
77 | } |
||
78 | |||
79 | if (isset($update_data['note'])) { |
||
80 | v::stringType()->assert($update_data['note']); |
||
81 | $form_params['note'] = (string)$update_data['note']; |
||
82 | } |
||
83 | |||
84 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
85 | Entity\Account::class, |
||
86 | $client->requestAPI('PATCH', '/api/v1/accounts/update_credentials', [ |
||
87 | 'form_params' => $form_params |
||
88 | ], $session) |
||
89 | ); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Getting an account's followers |
||
94 | * |
||
95 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#updating-the-current-user |
||
96 | * @param Client $client |
||
97 | * @param SessionStorage $session |
||
98 | * @param int $account_id |
||
99 | * @return Entity\Account[] |
||
100 | */ |
||
101 | public static function getAccountFollowers(Client $client, SessionStorage $session, $account_id) |
||
102 | { |
||
103 | v::intVal()->assert($account_id); |
||
104 | |||
105 | $query = []; |
||
106 | |||
107 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
108 | [Entity\Account::class], |
||
109 | $client->requestAPI('GET', sprintf('/api/v1/accounts/%d/followers', $account_id), [ |
||
110 | 'query' => $query |
||
111 | ], $session) |
||
112 | ); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Fetching a user's blocks |
||
117 | * |
||
118 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#updating-the-current-user |
||
119 | * @param Client $client |
||
120 | * @param SessionStorage $session |
||
121 | * @param array $options |
||
122 | * @return Entity\Account[] |
||
123 | */ |
||
124 | View Code Duplication | public static function getBlocks(Client $client, SessionStorage $session, $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
125 | { |
||
126 | $query = []; |
||
127 | |||
128 | if (isset($options['max_id'])) { |
||
129 | v::intVal()->min(0)->assert($options['max_id']); |
||
130 | $query['max_id'] = $options['max_id']; |
||
131 | } |
||
132 | |||
133 | if (isset($options['since_id'])) { |
||
134 | v::intVal()->min(0)->assert($options['since_id']); |
||
135 | $query['since_id'] = $options['since_id']; |
||
136 | } |
||
137 | |||
138 | if (isset($options['limit'])) { |
||
139 | v::intVal()->min(0)->assert($options['limit']); |
||
140 | $query['limit'] = $options['limit']; |
||
141 | } |
||
142 | |||
143 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
144 | [Entity\Account::class], |
||
145 | $client->requestAPI('GET', '/api/v1/blocks', [ |
||
146 | 'query' => $query, |
||
147 | ], $session) |
||
148 | ); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Fetching a user's favourites |
||
153 | * |
||
154 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#updating-the-current-user |
||
155 | * @param Client $client |
||
156 | * @param SessionStorage $session |
||
157 | * @param array $options |
||
158 | * @return Entity\Status[] |
||
159 | */ |
||
160 | View Code Duplication | public static function getFavourites(Client $client, SessionStorage $session, $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
161 | { |
||
162 | $query = []; |
||
163 | |||
164 | if (isset($options['max_id'])) { |
||
165 | v::intVal()->min(0)->assert($options['max_id']); |
||
166 | $query['max_id'] = $options['max_id']; |
||
167 | } |
||
168 | |||
169 | if (isset($options['since_id'])) { |
||
170 | v::intVal()->min(0)->assert($options['since_id']); |
||
171 | $query['since_id'] = $options['since_id']; |
||
172 | } |
||
173 | |||
174 | if (isset($options['limit'])) { |
||
175 | v::intVal()->min(0)->assert($options['limit']); |
||
176 | $query['limit'] = $options['limit']; |
||
177 | } |
||
178 | |||
179 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
180 | [Entity\Status::class], |
||
181 | $client->requestAPI('GET', '/api/v1/favourites', [ |
||
182 | 'query' => $query, |
||
183 | ], $session) |
||
184 | ); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Fetching a list of follow requests |
||
189 | * |
||
190 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#fetching-a-list-of-follow-requests |
||
191 | * @param Client $client |
||
192 | * @param SessionStorage $session |
||
193 | * @param array $options |
||
194 | * @return Entity\Accounts[] |
||
195 | */ |
||
196 | View Code Duplication | public static function getFollowRequests(Client $client, SessionStorage $session, $options = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
197 | { |
||
198 | $query = []; |
||
199 | |||
200 | if (isset($options['max_id'])) { |
||
201 | v::intVal()->min(0)->assert($options['max_id']); |
||
202 | $query['max_id'] = $options['max_id']; |
||
203 | } |
||
204 | |||
205 | if (isset($options['since_id'])) { |
||
206 | v::intVal()->min(0)->assert($options['since_id']); |
||
207 | $query['since_id'] = $options['since_id']; |
||
208 | } |
||
209 | |||
210 | if (isset($options['limit'])) { |
||
211 | v::intVal()->min(0)->assert($options['limit']); |
||
212 | $query['limit'] = $options['limit']; |
||
213 | } |
||
214 | |||
215 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
216 | [Entity\Account::class], |
||
217 | $client->requestAPI('GET', '/api/v1/follow_requests', [ |
||
218 | 'query' => $query, |
||
219 | ], $session) |
||
220 | ); |
||
221 | } |
||
222 | |||
223 | // |
||
224 | // Status API |
||
225 | // |
||
226 | |||
227 | /** |
||
228 | * Posting a new status |
||
229 | * |
||
230 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#posting-a-new-status |
||
231 | * @param Toot $toot |
||
232 | * @return Entity\Account |
||
233 | */ |
||
234 | public static function postStatus(Client $client, SessionStorage $session, Toot $toot) |
||
235 | { |
||
236 | $form_params = [ |
||
237 | 'status' => $toot->toot_string, |
||
238 | ]; |
||
239 | |||
240 | if ($toot->sensitive) { |
||
241 | $form_params['sensitive'] = 'true'; |
||
242 | } |
||
243 | |||
244 | if ($toot->in_reply_to_id) { |
||
0 ignored issues
–
show
The expression
$toot->in_reply_to_id of type integer|null is loosely compared to true ; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
245 | $form_params['in_reply_to_id'] = $toot->in_reply_to_id; |
||
246 | } |
||
247 | |||
248 | if (count($toot->media_ids) > 0) { |
||
249 | $form_params['media_ids'] = $toot->media_ids; |
||
250 | } |
||
251 | |||
252 | if ($toot->visibility === null) { |
||
253 | $form_params['visibility'] = $toot->visibility; |
||
254 | } |
||
255 | |||
256 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
257 | Entity\Status::class, |
||
258 | $client->requestAPI('POST', '/api/v1/statuses', [ |
||
259 | 'form_params' => $form_params |
||
260 | ], $session) |
||
261 | ); |
||
262 | } |
||
263 | |||
264 | // |
||
265 | // Timelines API |
||
266 | // |
||
267 | |||
268 | |||
269 | |||
270 | // |
||
271 | // Utility method |
||
272 | // |
||
273 | |||
274 | /** |
||
275 | * Getting an account's followers |
||
276 | * |
||
277 | * @see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#updating-the-current-user |
||
278 | * @param Client $client |
||
279 | * @param SessionStorage $session |
||
280 | * @param int $status_id |
||
281 | * @return Entity\Account[] |
||
282 | */ |
||
283 | View Code Duplication | public static function getStatus(Client $client, SessionStorage $session, $status_id) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
284 | { |
||
285 | v::intVal()->assert($status_id); |
||
286 | |||
287 | return static::map( |
||
0 ignored issues
–
show
Since
map() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self , or increase the visibility of map() to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return static::getTemperature();
}
} The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass {
private static function getTemperature() {
return "-182 °C";
}
}
print YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class YourClass
{
private static function getTemperature() {
return "3422 °C";
}
public static function getSomeVariable()
{
return self::getTemperature();
}
}
![]() |
|||
288 | Entity\Status::class, |
||
289 | $client->requestAPI('GET', sprintf('/api/v1/statuses/%d', $status_id), [], $session) |
||
290 | ); |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * @param string|string[] $class |
||
295 | * @param ResponseInterface $response |
||
296 | * @return Entity\Entity|Entity\Entity[] |
||
297 | */ |
||
298 | 1 | private static function map($class, ResponseInterface $response) |
|
299 | { |
||
300 | 1 | return Entity\map( |
|
301 | $class, |
||
302 | 1 | \GuzzleHttp\json_decode($response->getBody(), true) |
|
303 | ); |
||
304 | } |
||
305 | } |
||
306 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.