Passed
Push — master ( 15b43b...52c16b )
by y
01:45
created
src/Base/Data.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      * @param Api|Data $caller
47 47
      * @param array $data
48 48
      */
49
-    public function __construct ($caller, array $data = []) {
49
+    public function __construct($caller, array $data = []) {
50 50
         if ($caller instanceof self) {
51 51
             $this->api = $caller->api;
52 52
         }
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
      * @param array $args
68 68
      * @return mixed
69 69
      */
70
-    public function __call (string $method, array $args) {
70
+    public function __call(string $method, array $args) {
71 71
         static $magic = [];
72
-        if (!$call =& $magic[$method]) {
72
+        if (!$call = & $magic[$method]) {
73 73
             preg_match('/^(get|has|is|select|set)(.+)$/', $method, $call);
74 74
             $call[1] = '_' . $call[1];
75 75
             $call[2] = preg_replace_callback('/[A-Z]/', function(array $match) {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     /**
83 83
      * @return array
84 84
      */
85
-    public function __debugInfo (): array {
85
+    public function __debugInfo(): array {
86 86
         return $this->data;
87 87
     }
88 88
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @return null|Data|mixed
92 92
      * @internal `array_column()`
93 93
      */
94
-    final public function __get ($field) {
94
+    final public function __get($field) {
95 95
         return $this->_get($field);
96 96
     }
97 97
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      * @return bool
101 101
      * @internal `array_column()`
102 102
      */
103
-    final public function __isset ($field) {
103
+    final public function __isset($field) {
104 104
         return true;
105 105
     }
106 106
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      * @param string $field
113 113
      * @return mixed
114 114
      */
115
-    protected function _get (string $field) {
115
+    protected function _get(string $field) {
116 116
         return $this->data[$field] ?? null;
117 117
     }
118 118
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      * @param string $field
128 128
      * @return bool
129 129
      */
130
-    protected function _has (string $field): bool {
130
+    protected function _has(string $field): bool {
131 131
         $value = $this->_get($field);
132 132
         if (isset($value)) {
133 133
             if (is_countable($value)) {
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
      * @param mixed $item
146 146
      * @return mixed
147 147
      */
148
-    protected function _hydrate (string $class, $item) {
148
+    protected function _hydrate(string $class, $item) {
149 149
         if (!isset($item) or $item instanceof self) {
150 150
             return $item;
151 151
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * @param string $field
175 175
      * @return bool
176 176
      */
177
-    protected function _is (string $field): bool {
177
+    protected function _is(string $field): bool {
178 178
         return (bool)$this->_get($field);
179 179
     }
180 180
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @param callable $filter `fn( Data $object ): bool`
190 190
      * @return array
191 191
      */
192
-    protected function _select ($subject, callable $filter) {
192
+    protected function _select($subject, callable $filter) {
193 193
         if (is_string($subject)) {
194 194
             $subject = $this->_get($subject) ?? [];
195 195
         }
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      * @param mixed $value
212 212
      * @return $this
213 213
      */
214
-    protected function _set (string $field, $value) {
214
+    protected function _set(string $field, $value) {
215 215
         $this->data[$field] = $value;
216 216
         $this->diff[$field] = true;
217 217
         return $this;
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
      *
223 223
      * @param array $data
224 224
      */
225
-    protected function _setData (array $data): void {
225
+    protected function _setData(array $data): void {
226 226
         $this->data = $this->diff = [];
227 227
         foreach ($data as $field => $value) {
228 228
             $this->_setField($field, $value);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      * @param string $field
236 236
      * @param mixed $value
237 237
      */
238
-    protected function _setField (string $field, $value): void {
238
+    protected function _setField(string $field, $value): void {
239 239
         if (isset(static::MAP[$field])) {
240 240
             $class = static::MAP[$field];
241 241
             if (is_array($class)) {
@@ -256,14 +256,14 @@  discard block
 block discarded – undo
256 256
      *
257 257
      * @return bool
258 258
      */
259
-    final public function isDiff (): bool {
259
+    final public function isDiff(): bool {
260 260
         return (bool)$this->diff;
261 261
     }
262 262
 
263 263
     /**
264 264
      * @return array
265 265
      */
266
-    public function jsonSerialize (): array {
266
+    public function jsonSerialize(): array {
267 267
         $data = $this->toArray();
268 268
         ksort($data);
269 269
         return $data;
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
      *
275 275
      * @return string
276 276
      */
277
-    public function serialize (): string {
278
-        return json_encode($this, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
277
+    public function serialize(): string {
278
+        return json_encode($this, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
279 279
     }
280 280
 
281 281
     /**
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      * @param bool $diff
285 285
      * @return array
286 286
      */
287
-    public function toArray (bool $diff = false): array {
287
+    public function toArray(bool $diff = false): array {
288 288
         $dehydrate = function($each) use (&$dehydrate, $diff) {
289 289
             // convert entities to gids
290 290
             if ($each instanceof AbstractEntity and $each->hasGid()) {
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     /**
311 311
      * @param $serialized
312 312
      */
313
-    public function unserialize ($serialized): void {
313
+    public function unserialize($serialized): void {
314 314
         $this->data = json_decode($serialized, true);
315 315
     }
316 316
 }
317 317
\ No newline at end of file
Please login to merge, or discard this patch.
src/Base/AbstractEntity/UpdateTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
      *
17 17
      * @return $this
18 18
      */
19
-    public function update () {
19
+    public function update() {
20 20
         if ($this->isDiff()) {
21 21
             /** @var array $remote */
22 22
             $remote = $this->api->put($this, $this->toArray(true), ['expand' => 'this']);
Please login to merge, or discard this patch.
src/Base/AbstractEntity/CreateTrait.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
      *
17 17
      * @return string
18 18
      */
19
-    abstract protected function _getDir (): string;
19
+    abstract protected function _getDir(): string;
20 20
 
21 21
     /**
22 22
      * `POST` the new entity to Asana.
23 23
      *
24 24
      * @return $this
25 25
      */
26
-    public function create () {
26
+    public function create() {
27 27
         /** @var array $remote */
28 28
         $remote = $this->api->post($this->_getDir(), $this->toArray(true), ['expand' => 'this']);
29 29
         $this->_setData($remote);
Please login to merge, or discard this patch.
src/Base/AbstractEntity.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@  discard block
 block discarded – undo
31 31
      *
32 32
      * @return string
33 33
      */
34
-    abstract public function __toString (): string;
34
+    abstract public function __toString(): string;
35 35
 
36 36
     /**
37 37
      * @param self $entity
38 38
      * @return bool
39 39
      * @internal pool
40 40
      */
41
-    final public function __merge (self $entity): bool {
41
+    final public function __merge(self $entity): bool {
42 42
         $old = $this->toArray();
43 43
         $this->data = array_merge($this->data, array_diff_key($entity->data, $this->diff));
44 44
         return $this->toArray() !== $old;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @return $this
53 53
      * @internal
54 54
      */
55
-    protected function _addWithPost (string $addPath, array $data, string $field, array $diff) {
55
+    protected function _addWithPost(string $addPath, array $data, string $field, array $diff) {
56 56
         if ($this->hasGid()) {
57 57
             return $this->_setWithPost($addPath, $data, $field);
58 58
         }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      * @param string $field
66 66
      * @return mixed
67 67
      */
68
-    protected function _get (string $field) {
68
+    protected function _get(string $field) {
69 69
         if (!array_key_exists($field, $this->data) and $this->hasGid()) {
70 70
             $this->_reload($field);
71 71
         }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     /**
76 76
      * @param string $field
77 77
      */
78
-    protected function _reload (string $field): void {
78
+    protected function _reload(string $field): void {
79 79
         $remote = $this->api->get($this, [], ['fields' => static::OPT_FIELDS[$field] ?? $field]);
80 80
         $this->_setField($field, $remote[$field] ?? null);
81 81
         $this->api->getPool()->add($this);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * @return $this
90 90
      * @internal
91 91
      */
92
-    protected function _removeWithPost (string $rmPath, array $data, string $field, $diff) {
92
+    protected function _removeWithPost(string $rmPath, array $data, string $field, $diff) {
93 93
         if ($this->hasGid()) {
94 94
             return $this->_setWithPost($rmPath, $data, $field);
95 95
         }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         return $this->_set($field, array_values(array_filter($this->data[$field] ?? [], $diff)));
100 100
     }
101 101
 
102
-    protected function _setData (array $data): void {
102
+    protected function _setData(array $data): void {
103 103
         // meaningless once the entity is being created. it's constant.
104 104
         unset($data['resource_type'], $data['type']);
105 105
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      * @return $this
117 117
      * @internal
118 118
      */
119
-    protected function _setWithPost (string $path, array $data, string $field, $value = null) {
119
+    protected function _setWithPost(string $path, array $data, string $field, $value = null) {
120 120
         if ($this->hasGid()) {
121 121
             /** @var array $remote */
122 122
             $remote = $this->api->post($path, $data, ['fields' => static::OPT_FIELDS[$field] ?? $field]);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * @return null|string
134 134
      */
135
-    final public function getGid (): ?string {
135
+    final public function getGid(): ?string {
136 136
         return $this->data['gid'] ?? null;
137 137
     }
138 138
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      *
142 142
      * @return string[]
143 143
      */
144
-    public function getPoolKeys () {
144
+    public function getPoolKeys() {
145 145
         return [$this->getGid(), (string)$this];
146 146
     }
147 147
 
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
      *
151 151
      * @return string
152 152
      */
153
-    final public function getResourceType (): string {
153
+    final public function getResourceType(): string {
154 154
         return $this::TYPE;
155 155
     }
156 156
 
157 157
     /**
158 158
      * @return bool
159 159
      */
160
-    final public function hasGid (): bool {
160
+    final public function hasGid(): bool {
161 161
         return isset($this->data['gid']);
162 162
     }
163 163
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      * @depends after-create
168 168
      * @return $this
169 169
      */
170
-    public function reload () {
170
+    public function reload() {
171 171
         $remote = $this->api->get($this, [], ['expand' => 'this']);
172 172
         if (!isset($remote['gid'])) { // null and dir guard
173 173
             $this->api->getPool()->remove($this->getPoolKeys());
Please login to merge, or discard this patch.
src/Task/FieldEntry.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      *
28 28
      * @param array $data
29 29
      */
30
-    protected function _setData (array $data): void {
30
+    protected function _setData(array $data): void {
31 31
         if (isset($data['resource_subtype'])) {
32 32
             $tiny = array_intersect_key($data, array_flip([
33 33
                 'gid',
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
      * @param null|string $value
55 55
      * @return null|string
56 56
      */
57
-    protected function _toEnumOptionGid ($value) {
57
+    protected function _toEnumOptionGid($value) {
58 58
         return $this->getEnumOptionValues()[$value] ?? $value;
59 59
     }
60 60
 
61 61
     /**
62 62
      * @return string
63 63
      */
64
-    public function getCurrentOptionName () {
64
+    public function getCurrentOptionName() {
65 65
         return $this->getEnumOptionNames()[$this->getValue()];
66 66
     }
67 67
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      *
71 71
      * @return string[]
72 72
      */
73
-    public function getEnumOptionNames () {
73
+    public function getEnumOptionNames() {
74 74
         static $names = []; // shared
75 75
         $gid = $this->data['gid'];
76 76
         return $names[$gid] ?? $names[$gid] = array_column($this->data['enum_options'], 'name', 'gid');
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      *
82 82
      * @return string[]
83 83
      */
84
-    public function getEnumOptionValues () {
84
+    public function getEnumOptionValues() {
85 85
         static $values = []; // shared
86 86
         $gid = $this->data['gid'];
87 87
         return $values[$gid] ?? $values[$gid] = array_column($this->data['enum_options'], 'gid', 'name');
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     /**
91 91
      * @return null|number|string
92 92
      */
93
-    public function getValue () {
93
+    public function getValue() {
94 94
         $type = $this->data['type'];
95 95
         if ($type === CustomField::TYPE_ENUM) {
96 96
             return $this->data['enum_value']['gid'] ?? null;
@@ -101,21 +101,21 @@  discard block
 block discarded – undo
101 101
     /**
102 102
      * @return bool
103 103
      */
104
-    final public function isEnum (): bool {
104
+    final public function isEnum(): bool {
105 105
         return $this->getType() === CustomField::TYPE_ENUM;
106 106
     }
107 107
 
108 108
     /**
109 109
      * @return bool
110 110
      */
111
-    final public function isNumber (): bool {
111
+    final public function isNumber(): bool {
112 112
         return $this->getType() === CustomField::TYPE_NUMBER;
113 113
     }
114 114
 
115 115
     /**
116 116
      * @return bool
117 117
      */
118
-    final public function isText (): bool {
118
+    final public function isText(): bool {
119 119
         return $this->getType() === CustomField::TYPE_TEXT;
120 120
     }
121 121
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      * @param null|number|string $value
124 124
      * @return $this
125 125
      */
126
-    public function setValue ($value) {
126
+    public function setValue($value) {
127 127
         $type = $this->data['type'];
128 128
         $this->diff["{$type}_value"] = true;
129 129
         if ($type === CustomField::TYPE_ENUM) {
Please login to merge, or discard this patch.
src/Task/FieldEntries.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     protected $types = [];
51 51
 
52
-    public function __construct (Task $task, array $data = []) {
52
+    public function __construct(Task $task, array $data = []) {
53 53
         $this->task = $task;
54 54
         parent::__construct($task, $data);
55 55
     }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      * @param string $i
59 59
      * @param array $data
60 60
      */
61
-    protected function _setField (string $i, $data): void {
61
+    protected function _setField(string $i, $data): void {
62 62
         /** @var FieldEntry $entry */
63 63
         $entry = $this->api->factory($this, FieldEntry::class, $data);
64 64
         $gid = $entry->getGid();
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @param $offset
73 73
      * @return null|string
74 74
      */
75
-    protected function _toGid (string $offset) {
75
+    protected function _toGid(string $offset) {
76 76
         if (isset($this->names[$offset])) {
77 77
             return $offset;
78 78
         }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
     /**
83 83
      * @return int
84 84
      */
85
-    public function count () {
85
+    public function count() {
86 86
         return count($this->data);
87 87
     }
88 88
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
      * @param $fieldGid
91 91
      * @return FieldEntry
92 92
      */
93
-    public function getField ($fieldGid) {
93
+    public function getField($fieldGid) {
94 94
         return $this->data[$fieldGid];
95 95
     }
96 96
 
@@ -98,41 +98,41 @@  discard block
 block discarded – undo
98 98
      * @param string $name
99 99
      * @return string
100 100
      */
101
-    public function getGid (string $name): string {
101
+    public function getGid(string $name): string {
102 102
         return $this->gids[$name];
103 103
     }
104 104
 
105 105
     /**
106 106
      * @return string[]
107 107
      */
108
-    public function getGids () {
108
+    public function getGids() {
109 109
         return $this->gids;
110 110
     }
111 111
 
112 112
     /**
113 113
      * @return Generator
114 114
      */
115
-    public function getIterator () {
115
+    public function getIterator() {
116 116
         foreach ($this->data as $gid => $field) {
117 117
             yield $gid => $field->getValue();
118 118
         }
119 119
     }
120 120
 
121
-    public function getName (string $fieldGid) {
121
+    public function getName(string $fieldGid) {
122 122
         return $this->names[$fieldGid];
123 123
     }
124 124
 
125 125
     /**
126 126
      * @return string[]
127 127
      */
128
-    public function getNames () {
128
+    public function getNames() {
129 129
         return $this->names;
130 130
     }
131 131
 
132 132
     /**
133 133
      * @return array
134 134
      */
135
-    public function getValues () {
135
+    public function getValues() {
136 136
         return iterator_to_array($this);
137 137
     }
138 138
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      * @param string $offset
141 141
      * @return bool
142 142
      */
143
-    public function offsetExists ($offset) {
143
+    public function offsetExists($offset) {
144 144
         return isset($this->data[$this->_toGid($offset)]);
145 145
     }
146 146
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      * @param string $offset
149 149
      * @return null|number|string
150 150
      */
151
-    public function offsetGet ($offset) {
151
+    public function offsetGet($offset) {
152 152
         return $this->data[$this->_toGid($offset)]->getValue();
153 153
     }
154 154
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      * @param string $offset
157 157
      * @param null|number|string $value
158 158
      */
159
-    public function offsetSet ($offset, $value) {
159
+    public function offsetSet($offset, $value) {
160 160
         $offset = $this->_toGid($offset);
161 161
         $this->data[$offset]->setValue($value);
162 162
         $this->diff[$offset] = true;
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
      *
169 169
      * @param string $offset
170 170
      */
171
-    public function offsetUnset ($offset) {
171
+    public function offsetUnset($offset) {
172 172
         $this->offsetSet($offset, null);
173 173
     }
174 174
 
175
-    public function toArray (bool $diff = false): array {
175
+    public function toArray(bool $diff = false): array {
176 176
         if ($diff) {
177 177
             return array_map(function(FieldEntry $entry) {
178 178
                 return $entry->getValue();
Please login to merge, or discard this patch.