@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param string $token |
44 | 44 | * @param Pool|null $pool |
45 | 45 | */ |
46 | - public function __construct (string $token, Pool $pool = null) { |
|
46 | + public function __construct(string $token, Pool $pool = null) { |
|
47 | 47 | $this->token = $token; |
48 | 48 | $this->pool = $pool ?? new Pool(); |
49 | 49 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @return null|array |
58 | 58 | * @internal |
59 | 59 | */ |
60 | - protected function _exec (string $method, string $path, array $curlOpts = []) { |
|
60 | + protected function _exec(string $method, string $path, array $curlOpts = []) { |
|
61 | 61 | $log = $this->getLog(); |
62 | 62 | $log->log(LOG_DEBUG, "{$method} {$path}", $curlOpts); |
63 | 63 | /** @var resource $ch */ |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | switch ($curlInfo['http_code']) { |
89 | 89 | case 200: |
90 | 90 | case 201: |
91 | - return json_decode($body, true, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR); |
|
91 | + return json_decode($body, true, JSON_BIGINT_AS_STRING|JSON_THROW_ON_ERROR); |
|
92 | 92 | case 404: |
93 | 93 | return null; |
94 | 94 | case 429: |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @param string $path |
109 | 109 | */ |
110 | - public function delete (string $path): void { |
|
110 | + public function delete(string $path): void { |
|
111 | 111 | $this->_exec('DELETE', $path); |
112 | 112 | } |
113 | 113 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param array $data |
122 | 122 | * @return mixed|Data|AbstractEntity |
123 | 123 | */ |
124 | - public function factory ($caller, string $class, array $data = []) { |
|
124 | + public function factory($caller, string $class, array $data = []) { |
|
125 | 125 | return new $class($caller, $data); |
126 | 126 | } |
127 | 127 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param array $opt |
134 | 134 | * @return null|array |
135 | 135 | */ |
136 | - public function get (string $path, array $query = [], array $opt = []) { |
|
136 | + public function get(string $path, array $query = [], array $opt = []) { |
|
137 | 137 | foreach ($opt as $name => $value) { |
138 | 138 | $query["opt_{$name}"] = $value; |
139 | 139 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param string $gid |
148 | 148 | * @return null|Attachment |
149 | 149 | */ |
150 | - public function getAttachment (string $gid) { |
|
150 | + public function getAttachment(string $gid) { |
|
151 | 151 | return $this->load($this, Attachment::class, "attachments/{$gid}"); |
152 | 152 | } |
153 | 153 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param string $gid |
158 | 158 | * @return null|CustomField |
159 | 159 | */ |
160 | - public function getCustomField (string $gid) { |
|
160 | + public function getCustomField(string $gid) { |
|
161 | 161 | return $this->load($this, CustomField::class, "custom_fields/{$gid}"); |
162 | 162 | } |
163 | 163 | |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return Workspace |
169 | 169 | */ |
170 | - public function getDefaultWorkspace () { |
|
170 | + public function getDefaultWorkspace() { |
|
171 | 171 | return $this->getMe()->getDefaultWorkspace(); |
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
175 | 175 | * @return LoggerInterface |
176 | 176 | */ |
177 | - public function getLog () { |
|
177 | + public function getLog() { |
|
178 | 178 | return $this->log ?? $this->log = new NullLogger(); |
179 | 179 | } |
180 | 180 | |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return User |
185 | 185 | */ |
186 | - public function getMe () { |
|
186 | + public function getMe() { |
|
187 | 187 | return $this->getUser('me'); |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @return Pool |
192 | 192 | */ |
193 | - final public function getPool () { |
|
193 | + final public function getPool() { |
|
194 | 194 | return $this->pool; |
195 | 195 | } |
196 | 196 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param string $gid |
201 | 201 | * @return null|Portfolio |
202 | 202 | */ |
203 | - public function getPortfolio (string $gid) { |
|
203 | + public function getPortfolio(string $gid) { |
|
204 | 204 | return $this->load($this, Portfolio::class, "portfolios/{$gid}"); |
205 | 205 | } |
206 | 206 | |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param string $gid |
211 | 211 | * @return null|Project |
212 | 212 | */ |
213 | - public function getProject (string $gid) { |
|
213 | + public function getProject(string $gid) { |
|
214 | 214 | return $this->load($this, Project::class, "projects/{$gid}"); |
215 | 215 | } |
216 | 216 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param string $gid |
221 | 221 | * @return null|Section |
222 | 222 | */ |
223 | - public function getSection (string $gid) { |
|
223 | + public function getSection(string $gid) { |
|
224 | 224 | return $this->load($this, Section::class, "sections/{$gid}"); |
225 | 225 | } |
226 | 226 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @param string $gid |
231 | 231 | * @return null|Story |
232 | 232 | */ |
233 | - public function getStory (string $gid) { |
|
233 | + public function getStory(string $gid) { |
|
234 | 234 | return $this->load($this, Story::class, "stories/{$gid}"); |
235 | 235 | } |
236 | 236 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @param string $gid |
241 | 241 | * @return null|Tag |
242 | 242 | */ |
243 | - public function getTag (string $gid) { |
|
243 | + public function getTag(string $gid) { |
|
244 | 244 | return $this->load($this, Tag::class, "tags/{$gid}"); |
245 | 245 | } |
246 | 246 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param string $gid |
251 | 251 | * @return null|Task |
252 | 252 | */ |
253 | - public function getTask (string $gid) { |
|
253 | + public function getTask(string $gid) { |
|
254 | 254 | return $this->load($this, Task::class, "tasks/{$gid}"); |
255 | 255 | } |
256 | 256 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param string $gid |
261 | 261 | * @return null|TaskList |
262 | 262 | */ |
263 | - public function getTaskList (string $gid) { |
|
263 | + public function getTaskList(string $gid) { |
|
264 | 264 | return $this->load($this, TaskList::class, "user_task_lists/{$gid}"); |
265 | 265 | } |
266 | 266 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param string $gid |
271 | 271 | * @return null|Team |
272 | 272 | */ |
273 | - public function getTeam (string $gid) { |
|
273 | + public function getTeam(string $gid) { |
|
274 | 274 | return $this->load($this, Team::class, "teams/{$gid}"); |
275 | 275 | } |
276 | 276 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param string $gid |
281 | 281 | * @return null|User |
282 | 282 | */ |
283 | - public function getUser (string $gid) { |
|
283 | + public function getUser(string $gid) { |
|
284 | 284 | return $this->load($this, User::class, "users/{$gid}"); |
285 | 285 | } |
286 | 286 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | * @param string $gid |
289 | 289 | * @return ProjectWebhook|TaskWebhook |
290 | 290 | */ |
291 | - public function getWebhook (string $gid) { |
|
291 | + public function getWebhook(string $gid) { |
|
292 | 292 | return $this->pool->get($gid, $this, function() use ($gid) { |
293 | 293 | static $classes = [ |
294 | 294 | Project::TYPE => ProjectWebhook::class, |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @param array $data |
310 | 310 | * @return Event |
311 | 311 | */ |
312 | - public function getWebhookEvent (array $data) { |
|
312 | + public function getWebhookEvent(array $data) { |
|
313 | 313 | return $this->factory($this, Event::class, $data); |
314 | 314 | } |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @param string $gid |
320 | 320 | * @return null|Workspace |
321 | 321 | */ |
322 | - public function getWorkspace (string $gid) { |
|
322 | + public function getWorkspace(string $gid) { |
|
323 | 323 | return $this->load($this, Workspace::class, "workspaces/{$gid}"); |
324 | 324 | } |
325 | 325 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | * @param array $query |
333 | 333 | * @return null|mixed|AbstractEntity |
334 | 334 | */ |
335 | - public function load ($caller, string $class, string $path, array $query = []) { |
|
335 | + public function load($caller, string $class, string $path, array $query = []) { |
|
336 | 336 | $key = rtrim($path . '?' . http_build_query($query), '?'); |
337 | 337 | return $this->pool->get($key, $caller, function($caller) use ($class, $path, $query) { |
338 | 338 | if ($data = $this->get($path, $query, ['expand' => 'this'])) { |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | * @param array $query |
352 | 352 | * @return array|AbstractEntity[] |
353 | 353 | */ |
354 | - public function loadAll ($caller, string $class, string $path, array $query = []) { |
|
354 | + public function loadAll($caller, string $class, string $path, array $query = []) { |
|
355 | 355 | return iterator_to_array($this->loadEach(...func_get_args())); |
356 | 356 | } |
357 | 357 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @param array $query `limit` can exceed `100` here. |
367 | 367 | * @return Generator|AbstractEntity[] |
368 | 368 | */ |
369 | - public function loadEach ($caller, string $class, string $path, array $query = []) { |
|
369 | + public function loadEach($caller, string $class, string $path, array $query = []) { |
|
370 | 370 | $query['opt_expand'] = 'this'; |
371 | 371 | $remain = $query['limit'] ?? PHP_INT_MAX; |
372 | 372 | do { |
@@ -390,13 +390,13 @@ discard block |
||
390 | 390 | * @param array $opt |
391 | 391 | * @return null|array |
392 | 392 | */ |
393 | - public function post (string $path, array $data = [], array $opt = []) { |
|
393 | + public function post(string $path, array $data = [], array $opt = []) { |
|
394 | 394 | $response = $this->_exec('POST', $path, [ |
395 | 395 | CURLOPT_HTTPHEADER => ['Content-Type: application/json'], |
396 | 396 | CURLOPT_POSTFIELDS => json_encode([ |
397 | 397 | 'options' => $opt, |
398 | 398 | 'data' => $data |
399 | - ], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) |
|
399 | + ], JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR) |
|
400 | 400 | ]); |
401 | 401 | return $response['data'] ?? null; |
402 | 402 | } |
@@ -409,13 +409,13 @@ discard block |
||
409 | 409 | * @param array $opt |
410 | 410 | * @return null|array |
411 | 411 | */ |
412 | - public function put (string $path, array $data = [], array $opt = []) { |
|
412 | + public function put(string $path, array $data = [], array $opt = []) { |
|
413 | 413 | $response = $this->_exec('PUT', $path, [ |
414 | 414 | CURLOPT_HTTPHEADER => ['Content-Type: application/json'], |
415 | 415 | CURLOPT_POSTFIELDS => json_encode([ |
416 | 416 | 'options' => $opt, |
417 | 417 | 'data' => $data |
418 | - ], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR) |
|
418 | + ], JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR) |
|
419 | 419 | ]); |
420 | 420 | return $response['data'] ?? null; |
421 | 421 | } |
@@ -423,14 +423,14 @@ discard block |
||
423 | 423 | /** |
424 | 424 | * @param LoggerInterface $log |
425 | 425 | */ |
426 | - public function setLog (LoggerInterface $log) { |
|
426 | + public function setLog(LoggerInterface $log) { |
|
427 | 427 | $this->log = $log; |
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
431 | 431 | * @param Pool $pool |
432 | 432 | */ |
433 | - public function setPool (Pool $pool) { |
|
433 | + public function setPool(Pool $pool) { |
|
434 | 434 | $this->pool = $pool; |
435 | 435 | } |
436 | 436 | |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @param null|string $token Updated to the new token. |
448 | 448 | * @return Event[] |
449 | 449 | */ |
450 | - public function sync (string $gid, ?string &$token) { |
|
450 | + public function sync(string $gid, ?string &$token) { |
|
451 | 451 | try { |
452 | 452 | /** @var array $remote Asana throws 400 for missing entities here. */ |
453 | 453 | $remote = $this->_exec('GET', 'events?' . http_build_query([ |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | } |
459 | 459 | catch (AsanaError $error) { |
460 | 460 | if ($error->getCode() === 412) { |
461 | - $remote = json_decode($error->getMessage(), true, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR); |
|
461 | + $remote = json_decode($error->getMessage(), true, JSON_BIGINT_AS_STRING|JSON_THROW_ON_ERROR); |
|
462 | 462 | if (!isset($token)) { |
463 | 463 | // API docs say: "The response will be the same as for an expired sync token." |
464 | 464 | // The caller knowingly gave a null token, so we don't need to rethrow. |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | * @param string $to |
488 | 488 | * @return array |
489 | 489 | */ |
490 | - public function upload (string $file, string $to) { |
|
490 | + public function upload(string $file, string $to) { |
|
491 | 491 | return $this->_exec('POST', $to, [ |
492 | 492 | CURLOPT_POSTFIELDS => ['file' => new CURLFile(realpath($file))] // multipart/form-data |
493 | 493 | ])['data']; |