Passed
Push — master ( bcdfe5...bd5142 )
by y
02:13
created
src/Base/Data.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      * @param Api|Data $caller
31 31
      * @param array $data
32 32
      */
33
-    public function __construct ($caller, array $data = []) {
33
+    public function __construct($caller, array $data = []) {
34 34
         $this->api = $caller instanceof self ? $caller->api : $caller;
35 35
         $this->_setData($data);
36 36
     }
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
      * @param array $args
47 47
      * @return mixed
48 48
      */
49
-    public function __call (string $method, array $args) {
49
+    public function __call(string $method, array $args) {
50 50
         static $cache = [];
51
-        if (!$call =& $cache[$method]) {
51
+        if (!$call = & $cache[$method]) {
52 52
             preg_match('/^(get|has|is|set)(.+)$/', $method, $call);
53 53
             $call[1] = '_' . $call[1];
54 54
             $call[2] = preg_replace_callback('/[A-Z]/', function(array $match) {
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         return $this->{$call[1]}($call[2], ...$args);
59 59
     }
60 60
 
61
-    public function __debugInfo (): array {
61
+    public function __debugInfo(): array {
62 62
         return $this->data;
63 63
     }
64 64
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * @param string $key
71 71
      * @return mixed
72 72
      */
73
-    protected function _get (string $key) {
73
+    protected function _get(string $key) {
74 74
         return $this->data[$key] ?? null;
75 75
     }
76 76
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @return array
84 84
      */
85
-    protected function _getMap (): array {
85
+    protected function _getMap(): array {
86 86
         return [];
87 87
     }
88 88
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @param null|self|array $value
92 92
      * @return null|Data|Data[]
93 93
      */
94
-    protected function _getMapped ($class, $value) {
94
+    protected function _getMapped($class, $value) {
95 95
         // use empty|Data|Data[] as-is
96 96
         if (!$value or $value instanceof self or current($value) instanceof self) {
97 97
             return $value;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      * @param string $key
130 130
      * @return bool
131 131
      */
132
-    protected function _has (string $key): bool {
132
+    protected function _has(string $key): bool {
133 133
         $value = $this->_get($key);
134 134
         if (isset($value)) {
135 135
             if (is_countable($value)) {
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      * @param string $key
153 153
      * @return bool
154 154
      */
155
-    protected function _is (string $key): bool {
155
+    protected function _is(string $key): bool {
156 156
         return !empty($this->_get($key));
157 157
     }
158 158
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      * @param mixed $value
166 166
      * @return $this
167 167
      */
168
-    protected function _set (string $key, $value) {
168
+    protected function _set(string $key, $value) {
169 169
         $this->data[$key] = $value;
170 170
         $this->diff[$key] = true;
171 171
         return $this;
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      * @param array $data
178 178
      * @return $this
179 179
      */
180
-    protected function _setData (array $data) {
180
+    protected function _setData(array $data) {
181 181
         $map = $this->_getMap();
182 182
         /** @var null|self|array $value */
183 183
         foreach (array_intersect_key($data, $map) as $key => $value) {
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @param array $data
196 196
      * @return mixed
197 197
      */
198
-    final protected function factory (string $class, array $data = []) {
198
+    final protected function factory(string $class, array $data = []) {
199 199
         return $this->api->factory($class, $this, $data);
200 200
     }
201 201
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      *
205 205
      * @return array
206 206
      */
207
-    public function getDiff (): array {
207
+    public function getDiff(): array {
208 208
         $convert = function($each) use (&$convert) {
209 209
             // convert existing entities to gids
210 210
             if ($each instanceof AbstractEntity and $each->hasGid()) {
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      *
230 230
      * @return bool
231 231
      */
232
-    public function isDiff (): bool {
232
+    public function isDiff(): bool {
233 233
         return (bool)$this->diff;
234 234
     }
235 235
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
      * @see toArray()
238 238
      * @return array
239 239
      */
240
-    public function jsonSerialize (): array {
240
+    public function jsonSerialize(): array {
241 241
         return $this->toArray();
242 242
     }
243 243
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      * @param array $query
252 252
      * @return null|mixed|AbstractEntity
253 253
      */
254
-    final protected function load (string $class, string $path, array $query = []) {
254
+    final protected function load(string $class, string $path, array $query = []) {
255 255
         return $this->api->load($class, $this, $path, $query);
256 256
     }
257 257
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      * @param int $pages
267 267
      * @return array|AbstractEntity[]
268 268
      */
269
-    final protected function loadAll (string $class, string $path, array $query = [], int $pages = 0) {
269
+    final protected function loadAll(string $class, string $path, array $query = [], int $pages = 0) {
270 270
         return $this->api->loadAll($class, $this, $path, $query, $pages);
271 271
     }
272 272
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
      *
276 276
      * @return string
277 277
      */
278
-    public function serialize (): string {
278
+    public function serialize(): string {
279 279
         return serialize($this->toArray());
280 280
     }
281 281
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      *
285 285
      * @return array
286 286
      */
287
-    public function toArray (): array {
287
+    public function toArray(): array {
288 288
         if (!$this->api) {
289 289
             return $this->data;
290 290
         }
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
      *
309 309
      * @param $serialized
310 310
      */
311
-    public function unserialize ($serialized): void {
311
+    public function unserialize($serialized): void {
312 312
         $this->api = Api::getDefault();
313 313
         $this->data = unserialize($serialized);
314 314
     }
Please login to merge, or discard this patch.
src/Api.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -52,24 +52,24 @@  discard block
 block discarded – undo
52 52
     /**
53 53
      * @return Cache
54 54
      */
55
-    public static function getCache () {
55
+    public static function getCache() {
56 56
         return static::$cache ?? static::$cache = new Cache();
57 57
     }
58 58
 
59 59
     /**
60 60
      * @return Api
61 61
      */
62
-    public static function getDefault () {
62
+    public static function getDefault() {
63 63
         return self::$default;
64 64
     }
65 65
 
66 66
     /**
67 67
      * @return LoggerInterface
68 68
      */
69
-    public static function getLogger () {
69
+    public static function getLogger() {
70 70
         return static::$logger ?? static::$logger = new class implements LoggerInterface {
71 71
 
72
-                public function log (string $info, string $path, ?array $payload): void {
72
+                public function log(string $info, string $path, ?array $payload): void {
73 73
                     // stub
74 74
                 }
75 75
 
@@ -79,28 +79,28 @@  discard block
 block discarded – undo
79 79
     /**
80 80
      * @param Cache $cache
81 81
      */
82
-    public static function setCache (Cache $cache) {
82
+    public static function setCache(Cache $cache) {
83 83
         static::$cache = $cache;
84 84
     }
85 85
 
86 86
     /**
87 87
      * @param Api $default
88 88
      */
89
-    public static function setDefault (Api $default) {
89
+    public static function setDefault(Api $default) {
90 90
         self::$default = $default;
91 91
     }
92 92
 
93 93
     /**
94 94
      * @param LoggerInterface $logger
95 95
      */
96
-    public static function setLogger (LoggerInterface $logger) {
96
+    public static function setLogger(LoggerInterface $logger) {
97 97
         static::$logger = $logger;
98 98
     }
99 99
 
100 100
     /**
101 101
      * @param string $token
102 102
      */
103
-    public function __construct (string $token) {
103
+    public function __construct(string $token) {
104 104
         $this->token = $token;
105 105
         if (!static::$default) {
106 106
             static::$default = $this;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @param string $path
114 114
      */
115
-    public function delete (string $path): void {
115
+    public function delete(string $path): void {
116 116
         $this->exec('DELETE', $path);
117 117
     }
118 118
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      * @return null|array
124 124
      * @internal
125 125
      */
126
-    protected function exec (string $method, string $path, array $opts = null) {
126
+    protected function exec(string $method, string $path, array $opts = null) {
127 127
         $ch = curl_init();
128 128
         curl_setopt_array($ch, [
129 129
             CURLOPT_CUSTOMREQUEST => $method,
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * @param array $data
175 175
      * @return mixed
176 176
      */
177
-    public function factory (string $class, $caller, array $data = []) {
177
+    public function factory(string $class, $caller, array $data = []) {
178 178
         return new $class($caller, $data);
179 179
     }
180 180
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      * @param array $options
187 187
      * @return null|array
188 188
      */
189
-    public function get (string $path, array $query = [], array $options = []) {
189
+    public function get(string $path, array $query = [], array $options = []) {
190 190
         foreach ($options as $name => $value) {
191 191
             $query["opt_{$name}"] = $value;
192 192
         }
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      * @param string $gid
201 201
      * @return null|Attachment
202 202
      */
203
-    public function getAttachment (string $gid) {
203
+    public function getAttachment(string $gid) {
204 204
         return $this->load(Attachment::class, $this, "attachments/{$gid}");
205 205
     }
206 206
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
      * @param string $gid
211 211
      * @return null|CustomField
212 212
      */
213
-    public function getCustomField (string $gid) {
213
+    public function getCustomField(string $gid) {
214 214
         return $this->load(CustomField::class, $this, "custom_fields/{$gid}");
215 215
     }
216 216
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      *
220 220
      * @return User
221 221
      */
222
-    public function getMe () {
222
+    public function getMe() {
223 223
         return $this->getUser('me');
224 224
     }
225 225
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      * @param array $query
231 231
      * @return string
232 232
      */
233
-    protected function getPath (string $path, array $query): string {
233
+    protected function getPath(string $path, array $query): string {
234 234
         return $query ? $path . '?' . http_build_query($query) : $path;
235 235
     }
236 236
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      * @param string $gid
241 241
      * @return null|Portfolio
242 242
      */
243
-    public function getPortfolio (string $gid) {
243
+    public function getPortfolio(string $gid) {
244 244
         return $this->load(Portfolio::class, $this, "portfolios/{$gid}");
245 245
     }
246 246
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
      * @param string $gid
251 251
      * @return null|Project
252 252
      */
253
-    public function getProject (string $gid) {
253
+    public function getProject(string $gid) {
254 254
         return $this->load(Project::class, $this, "projects/{$gid}");
255 255
     }
256 256
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      * @param string $gid
261 261
      * @return null|Section
262 262
      */
263
-    public function getSection (string $gid) {
263
+    public function getSection(string $gid) {
264 264
         return $this->load(Section::class, $this, "sections/{$gid}");
265 265
     }
266 266
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
      * @param string $gid
271 271
      * @return null|Story
272 272
      */
273
-    public function getStory (string $gid) {
273
+    public function getStory(string $gid) {
274 274
         return $this->load(Story::class, $this, "stories/{$gid}");
275 275
     }
276 276
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
      * @param string $gid
281 281
      * @return null|Tag
282 282
      */
283
-    public function getTag (string $gid) {
283
+    public function getTag(string $gid) {
284 284
         return $this->load(Tag::class, $this, "tags/{$gid}");
285 285
     }
286 286
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * @param string $gid
291 291
      * @return null|Task
292 292
      */
293
-    public function getTask (string $gid) {
293
+    public function getTask(string $gid) {
294 294
         return $this->load(Task::class, $this, "tasks/{$gid}");
295 295
     }
296 296
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      * @param string $gid
301 301
      * @return null|Team
302 302
      */
303
-    public function getTeam (string $gid) {
303
+    public function getTeam(string $gid) {
304 304
         return $this->load(Team::class, $this, "teams/{$gid}");
305 305
     }
306 306
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      * @param string $gid
311 311
      * @return null|User
312 312
      */
313
-    public function getUser (string $gid) {
313
+    public function getUser(string $gid) {
314 314
         return $this->load(User::class, $this, "users/{$gid}");
315 315
     }
316 316
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
      * @param array $data
323 323
      * @return ProjectEvent|TaskEvent|StoryEvent
324 324
      */
325
-    public function getWebhookEvent (array $data) {
325
+    public function getWebhookEvent(array $data) {
326 326
         static $classes = [
327 327
             Project::TYPE => ProjectEvent::class,
328 328
             Task::TYPE => TaskEvent::class,
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      * @param string $gid
336 336
      * @return null|Workspace
337 337
      */
338
-    public function getWorkspace (string $gid) {
338
+    public function getWorkspace(string $gid) {
339 339
         return $this->load(Workspace::class, $this, "workspaces/{$gid}");
340 340
     }
341 341
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
      * @param string $name
344 344
      * @return null|Workspace
345 345
      */
346
-    public function getWorkspaceByName (string $name) {
346
+    public function getWorkspaceByName(string $name) {
347 347
         foreach ($this->getMe()->getWorkspaces() as $workspace) {
348 348
             if ($workspace->getName() === $name) {
349 349
                 return $workspace;
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
      * @param string $json
357 357
      * @return null|array
358 358
      */
359
-    protected function jsonDecode (string $json) {
360
-        return json_decode($json, true, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR);
359
+    protected function jsonDecode(string $json) {
360
+        return json_decode($json, true, JSON_BIGINT_AS_STRING|JSON_THROW_ON_ERROR);
361 361
     }
362 362
 
363 363
     /**
364 364
      * @param array $data
365 365
      * @return string
366 366
      */
367
-    protected function jsonEncode (array $data): string {
368
-        return json_encode($data, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);
367
+    protected function jsonEncode(array $data): string {
368
+        return json_encode($data, JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR);
369 369
     }
370 370
 
371 371
     /**
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
      * @param array $query
380 380
      * @return null|mixed|AbstractEntity
381 381
      */
382
-    public function load (string $class, $caller, string $path, array $query = []) {
382
+    public function load(string $class, $caller, string $path, array $query = []) {
383 383
         $key = $this->getPath($path, $query);
384 384
         return $this->getCache()->get($key, $caller, function($caller) use ($class, $path, $query) {
385 385
             $data = $this->get($path, $query, ['expand' => 'this']);
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      * @param int $pages If positive, stops after this many pages have been fetched.
400 400
      * @return array|AbstractEntity[]
401 401
      */
402
-    public function loadAll (string $class, $caller, string $path, array $query = [], int $pages = 0) {
402
+    public function loadAll(string $class, $caller, string $path, array $query = [], int $pages = 0) {
403 403
         $query['opt_expand'] = 'this';
404 404
         $query += ['limit' => 100];
405 405
         $path = $this->getPath($path, $query);
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
      * @param array $options
426 426
      * @return null|array
427 427
      */
428
-    public function post (string $path, array $data = [], array $options = []) {
428
+    public function post(string $path, array $data = [], array $options = []) {
429 429
         $response = $this->exec('POST', $path, [
430 430
             CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
431 431
             CURLOPT_POSTFIELDS => $this->jsonEncode(['options' => $options, 'data' => $data])
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
      * @param array $options
442 442
      * @return null|array
443 443
      */
444
-    public function put (string $path, array $data = [], array $options = []) {
444
+    public function put(string $path, array $data = [], array $options = []) {
445 445
         $response = $this->exec('PUT', $path, [
446 446
             CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
447 447
             CURLOPT_POSTFIELDS => $this->jsonEncode(['options' => $options, 'data' => $data])
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
      * @param null|string $token
461 461
      * @return ProjectEvent[]|TaskEvent[]|StoryEvent[]
462 462
      */
463
-    public function sync ($entity, &$token) {
463
+    public function sync($entity, &$token) {
464 464
         try {
465 465
             $response = $this->exec('GET', $this->getPath('events', [
466 466
                 'resource' => $entity->getGid(),
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
      * @param string $file
493 493
      * @return null|array
494 494
      */
495
-    public function upload (string $path, string $file) {
495
+    public function upload(string $path, string $file) {
496 496
         $response = $this->exec('POST', $path, [
497 497
             CURLOPT_POSTFIELDS => ['file' => new CURLFile(realpath($file))] // multipart/form-data
498 498
         ]);
Please login to merge, or discard this patch.