@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | const NAME = 'asana'; |
| 19 | 19 | |
| 20 | - public function boot () { |
|
| 20 | + public function boot() { |
|
| 21 | 21 | $this->publishes([ |
| 22 | 22 | __DIR__ . '/config/asana.php' => $this->app->configPath('asana.php') |
| 23 | 23 | ]); |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function provides () { |
|
| 33 | + public function provides() { |
|
| 34 | 34 | return [self::NAME]; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - public function register () { |
|
| 37 | + public function register() { |
|
| 38 | 38 | $this->app->singleton(self::NAME, function(Application $app) { |
| 39 | 39 | $config = $app['config'][self::NAME]; |
| 40 | 40 | $pool = null; |
@@ -29,30 +29,30 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @param string $dir |
| 31 | 31 | */ |
| 32 | - public function __construct (string $dir) { |
|
| 32 | + public function __construct(string $dir) { |
|
| 33 | 33 | $this->dir = $dir; |
| 34 | 34 | $this->log = new NullLogger(); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - private function _log (string $msg): void { |
|
| 37 | + private function _log(string $msg): void { |
|
| 38 | 38 | $this->log->log(LOG_DEBUG, $msg); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - private function _path ($key): string { |
|
| 41 | + private function _path($key): string { |
|
| 42 | 42 | $path = "{$this->dir}/{$key}~"; |
| 43 | 43 | clearstatcache(true, $path); |
| 44 | 44 | return $path; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private function _ref ($key): string { |
|
| 47 | + private function _ref($key): string { |
|
| 48 | 48 | return $ref = "{$this->dir}/{$key}.ref"; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function clear () { |
|
| 51 | + public function clear() { |
|
| 52 | 52 | // unused. just delete the dir. |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public function delete ($key) { |
|
| 55 | + public function delete($key) { |
|
| 56 | 56 | $path = $this->_path($key); |
| 57 | 57 | if (is_link($ref = $this->_ref($key))) { |
| 58 | 58 | $this->_log("CACHE DELINK {$key}"); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function deleteMultiple ($keys) { |
|
| 68 | + public function deleteMultiple($keys) { |
|
| 69 | 69 | // unused |
| 70 | 70 | } |
| 71 | 71 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param null $default |
| 75 | 75 | * @return null|string|object |
| 76 | 76 | */ |
| 77 | - public function get ($key, $default = null) { |
|
| 77 | + public function get($key, $default = null) { |
|
| 78 | 78 | $path = $this->_path($key); |
| 79 | 79 | if (!is_file($path)) { |
| 80 | 80 | $this->_log("CACHE MISS {$key}"); |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | return $data; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function getMultiple ($keys, $default = null) { |
|
| 96 | + public function getMultiple($keys, $default = null) { |
|
| 97 | 97 | // unused |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function has ($key): bool { |
|
| 100 | + public function has($key): bool { |
|
| 101 | 101 | return is_file($this->_path($key)); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @param int $ttl |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - public function set ($key, $value, $ttl = null): void { |
|
| 110 | + public function set($key, $value, $ttl = null): void { |
|
| 111 | 111 | $path = $this->_path($key); |
| 112 | 112 | if (!is_dir(dirname($path))) { |
| 113 | 113 | mkdir(dirname($path), 0770, true); |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | * @param LoggerInterface $log |
| 137 | 137 | * @return $this |
| 138 | 138 | */ |
| 139 | - public function setLog (LoggerInterface $log) { |
|
| 139 | + public function setLog(LoggerInterface $log) { |
|
| 140 | 140 | $this->log = $log; |
| 141 | 141 | return $this; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - public function setMultiple ($values, $ttl = null) { |
|
| 144 | + public function setMultiple($values, $ttl = null) { |
|
| 145 | 145 | // unused |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | \ No newline at end of file |
@@ -58,8 +58,7 @@ discard block |
||
| 58 | 58 | $this->_log("CACHE DELINK {$key}"); |
| 59 | 59 | unlink($ref); |
| 60 | 60 | unlink($path); |
| 61 | - } |
|
| 62 | - elseif (is_file($path)) { |
|
| 61 | + } elseif (is_file($path)) { |
|
| 63 | 62 | $this->_log("CACHE DELETE {$key}"); |
| 64 | 63 | unlink($path); |
| 65 | 64 | } |
@@ -117,8 +116,7 @@ discard block |
||
| 117 | 116 | ["CACHE SET {$key}", "CACHE BURN {$key}"][$value instanceof ImmutableInterface], |
| 118 | 117 | "CACHE UPDATE {$key}" |
| 119 | 118 | ][is_file($path)]); |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | $this->_log([ |
| 123 | 121 | "CACHE LINK {$key} => {$value}", |
| 124 | 122 | "CACHE RENEW LINK {$key} => {$value}" |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * @param AbstractEntity $entity |
| 31 | 31 | */ |
| 32 | - protected function _add (AbstractEntity $entity): void { |
|
| 32 | + protected function _add(AbstractEntity $entity): void { |
|
| 33 | 33 | $gid = $entity->getGid(); |
| 34 | 34 | $this->entities[$gid] = $entity; |
| 35 | 35 | $this->gids[$gid] = $gid; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param AbstractEntity $entity |
| 40 | 40 | * @param string[] $keys |
| 41 | 41 | */ |
| 42 | - protected function _addKeys (AbstractEntity $entity, ...$keys): void { |
|
| 42 | + protected function _addKeys(AbstractEntity $entity, ...$keys): void { |
|
| 43 | 43 | $this->gids += array_fill_keys($keys, $entity->getGid()); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param Api|Data $caller For hydration if needed. |
| 49 | 49 | * @return null|AbstractEntity |
| 50 | 50 | */ |
| 51 | - protected function _get (string $key, $caller) { |
|
| 51 | + protected function _get(string $key, $caller) { |
|
| 52 | 52 | if (isset($this->gids[$key])) { |
| 53 | 53 | return $this->entities[$this->gids[$key]]; |
| 54 | 54 | } |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | * @param string $key |
| 63 | 63 | * @return bool |
| 64 | 64 | */ |
| 65 | - protected function _has (string $key): bool { |
|
| 65 | + protected function _has(string $key): bool { |
|
| 66 | 66 | return isset($this->gids[$key]); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * @param AbstractEntity $entity |
| 71 | 71 | */ |
| 72 | - final public function add (AbstractEntity $entity): void { |
|
| 72 | + final public function add(AbstractEntity $entity): void { |
|
| 73 | 73 | if (!$entity->isDiff()) { |
| 74 | 74 | $this->_add($entity); |
| 75 | 75 | $this->_addKeys($entity, ...$entity->getPoolKeys()); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param Closure $factory `fn( Api|Data $caller ): null|AbstractEntity` |
| 83 | 83 | * @return null|mixed|AbstractEntity |
| 84 | 84 | */ |
| 85 | - final public function get (string $key, $caller, Closure $factory) { |
|
| 85 | + final public function get(string $key, $caller, Closure $factory) { |
|
| 86 | 86 | /** @var AbstractEntity $entity */ |
| 87 | 87 | if (!$entity = $this->_get($key, $caller) and $entity = $factory($caller)) { |
| 88 | 88 | $gid = $entity->getGid(); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | /** |
| 104 | 104 | * @param string[] $keys |
| 105 | 105 | */ |
| 106 | - public function remove (array $keys): void { |
|
| 106 | + public function remove(array $keys): void { |
|
| 107 | 107 | foreach ($keys as $key) { |
| 108 | 108 | unset($this->entities[$key]); |
| 109 | 109 | unset($this->gids[$key]); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param Api|Data $caller |
| 58 | 58 | * @param array $data |
| 59 | 59 | */ |
| 60 | - public function __construct ($caller, array $data = []) { |
|
| 60 | + public function __construct($caller, array $data = []) { |
|
| 61 | 61 | if ($caller instanceof self) { |
| 62 | 62 | $this->api = $caller->api; |
| 63 | 63 | } |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @param array $args |
| 79 | 79 | * @return mixed |
| 80 | 80 | */ |
| 81 | - public function __call (string $method, array $args) { |
|
| 81 | + public function __call(string $method, array $args) { |
|
| 82 | 82 | static $magic = []; |
| 83 | - if (!$call =& $magic[$method]) { |
|
| 83 | + if (!$call = & $magic[$method]) { |
|
| 84 | 84 | preg_match('/^(get|has|is|select|set)(.+)$/', $method, $call); |
| 85 | 85 | $call[1] = '_' . $call[1]; |
| 86 | 86 | $call[2] = preg_replace_callback('/[A-Z]/', function(array $match) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | /** |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - public function __debugInfo (): array { |
|
| 96 | + public function __debugInfo(): array { |
|
| 97 | 97 | return $this->data; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @return null|Data|mixed |
| 103 | 103 | * @internal `array_column()` |
| 104 | 104 | */ |
| 105 | - final public function __get ($field) { |
|
| 105 | + final public function __get($field) { |
|
| 106 | 106 | return $this->_get($field); |
| 107 | 107 | } |
| 108 | 108 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return bool |
| 112 | 112 | * @internal `array_column()` |
| 113 | 113 | */ |
| 114 | - final public function __isset ($field) { |
|
| 114 | + final public function __isset($field) { |
|
| 115 | 115 | return true; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param string $field |
| 124 | 124 | * @return mixed |
| 125 | 125 | */ |
| 126 | - protected function _get (string $field) { |
|
| 126 | + protected function _get(string $field) { |
|
| 127 | 127 | return $this->data[$field] ?? null; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @param string $field |
| 139 | 139 | * @return bool |
| 140 | 140 | */ |
| 141 | - protected function _has (string $field): bool { |
|
| 141 | + protected function _has(string $field): bool { |
|
| 142 | 142 | $value = $this->_get($field); |
| 143 | 143 | if (isset($value)) { |
| 144 | 144 | if (is_countable($value)) { |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param string $field |
| 162 | 162 | * @return bool |
| 163 | 163 | */ |
| 164 | - protected function _is (string $field): bool { |
|
| 164 | + protected function _is(string $field): bool { |
|
| 165 | 165 | return (bool)$this->_get($field); |
| 166 | 166 | } |
| 167 | 167 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * @param callable $filter `fn( Data $object ): bool` |
| 177 | 177 | * @return array |
| 178 | 178 | */ |
| 179 | - protected function _select ($subject, callable $filter) { |
|
| 179 | + protected function _select($subject, callable $filter) { |
|
| 180 | 180 | if (!is_iterable($subject)) { |
| 181 | 181 | $subject = $this->_get($subject) ?? []; |
| 182 | 182 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param mixed $value |
| 199 | 199 | * @return $this |
| 200 | 200 | */ |
| 201 | - protected function _set (string $field, $value) { |
|
| 201 | + protected function _set(string $field, $value) { |
|
| 202 | 202 | $this->data[$field] = $value; |
| 203 | 203 | $this->diff[$field] = true; |
| 204 | 204 | return $this; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * |
| 210 | 210 | * @param array $data |
| 211 | 211 | */ |
| 212 | - protected function _setData (array $data): void { |
|
| 212 | + protected function _setData(array $data): void { |
|
| 213 | 213 | $this->data = $this->diff = []; |
| 214 | 214 | foreach ($data as $field => $value) { |
| 215 | 215 | $this->_setMapped($field, $value); |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @param string $field |
| 223 | 223 | * @param mixed $value |
| 224 | 224 | */ |
| 225 | - protected function _setMapped (string $field, $value): void { |
|
| 225 | + protected function _setMapped(string $field, $value): void { |
|
| 226 | 226 | unset($this->diff[$field]); |
| 227 | 227 | |
| 228 | 228 | // use value as-is? |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return array |
| 276 | 276 | */ |
| 277 | - public function getDiff (): array { |
|
| 277 | + public function getDiff(): array { |
|
| 278 | 278 | $convert = function($each) use (&$convert) { |
| 279 | 279 | // convert existing entities to gids |
| 280 | 280 | if ($each instanceof AbstractEntity and $each->hasGid()) { |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * @param string null $field |
| 301 | 301 | * @return bool |
| 302 | 302 | */ |
| 303 | - final public function isDiff (string $field = null): bool { |
|
| 303 | + final public function isDiff(string $field = null): bool { |
|
| 304 | 304 | if ($field) { |
| 305 | 305 | return isset($this->diff[$field]); |
| 306 | 306 | } |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @see toArray() |
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | - public function jsonSerialize (): array { |
|
| 314 | + public function jsonSerialize(): array { |
|
| 315 | 315 | $data = $this->toArray(); |
| 316 | 316 | ksort($data); |
| 317 | 317 | return $data; |
@@ -322,8 +322,8 @@ discard block |
||
| 322 | 322 | * |
| 323 | 323 | * @return string |
| 324 | 324 | */ |
| 325 | - public function serialize (): string { |
|
| 326 | - return json_encode($this, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
| 325 | + public function serialize(): string { |
|
| 326 | + return json_encode($this, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * |
| 332 | 332 | * @return array |
| 333 | 333 | */ |
| 334 | - public function toArray (): array { |
|
| 334 | + public function toArray(): array { |
|
| 335 | 335 | if (!$this->api) { |
| 336 | 336 | return $this->data; |
| 337 | 337 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | /** |
| 357 | 357 | * @param $serialized |
| 358 | 358 | */ |
| 359 | - public function unserialize ($serialized): void { |
|
| 359 | + public function unserialize($serialized): void { |
|
| 360 | 360 | $this->data = json_decode($serialized, true); |
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | \ No newline at end of file |
@@ -60,8 +60,7 @@ discard block |
||
| 60 | 60 | public function __construct ($caller, array $data = []) { |
| 61 | 61 | if ($caller instanceof self) { |
| 62 | 62 | $this->api = $caller->api; |
| 63 | - } |
|
| 64 | - else { |
|
| 63 | + } else { |
|
| 65 | 64 | $this->api = $caller; |
| 66 | 65 | } |
| 67 | 66 | $this->_setData($data); |
@@ -263,8 +262,7 @@ discard block |
||
| 263 | 262 | |
| 264 | 263 | if ($isList) { |
| 265 | 264 | $this->data[$field] = array_map($hydrate, $value); |
| 266 | - } |
|
| 267 | - else { |
|
| 265 | + } else { |
|
| 268 | 266 | $this->data[$field] = $hydrate($value); |
| 269 | 267 | } |
| 270 | 268 | } |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - abstract public function __toString (): string; |
|
| 33 | + abstract public function __toString(): string; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * @param self $entity |
| 37 | 37 | * @return bool |
| 38 | 38 | * @internal pool |
| 39 | 39 | */ |
| 40 | - final public function __merge (self $entity): bool { |
|
| 40 | + final public function __merge(self $entity): bool { |
|
| 41 | 41 | $old = $this->toArray(); |
| 42 | 42 | $this->data = array_merge($this->data, array_diff_key($entity->data, $this->diff)); |
| 43 | 43 | return $this->toArray() !== $old; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return $this |
| 52 | 52 | * @internal |
| 53 | 53 | */ |
| 54 | - protected function _addWithPost (string $addPath, array $data, string $field, array $diff) { |
|
| 54 | + protected function _addWithPost(string $addPath, array $data, string $field, array $diff) { |
|
| 55 | 55 | if ($this->hasGid()) { |
| 56 | 56 | return $this->_setWithPost($addPath, $data, $field); |
| 57 | 57 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @internal |
| 65 | 65 | */ |
| 66 | - protected function _delete (): void { |
|
| 66 | + protected function _delete(): void { |
|
| 67 | 67 | $this->api->delete($this); |
| 68 | 68 | $this->api->getPool()->remove($this->getPoolKeys()); |
| 69 | 69 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @param string $field |
| 75 | 75 | * @return mixed |
| 76 | 76 | */ |
| 77 | - protected function _get (string $field) { |
|
| 77 | + protected function _get(string $field) { |
|
| 78 | 78 | if (!array_key_exists($field, $this->data) and $this->hasGid()) { |
| 79 | 79 | $this->reload($field); |
| 80 | 80 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 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 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @return $this |
| 107 | 107 | * @internal |
| 108 | 108 | */ |
| 109 | - protected function _save (string $dir = null) { |
|
| 109 | + protected function _save(string $dir = null) { |
|
| 110 | 110 | if (isset($dir)) { // create() |
| 111 | 111 | $remote = $this->api->post($dir, $this->getDiff(), ['expand' => 'this']); |
| 112 | 112 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | return $this; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - protected function _setData (array $data): void { |
|
| 125 | + protected function _setData(array $data): void { |
|
| 126 | 126 | // make sure the gid is consistently null|string across all entities. |
| 127 | 127 | $data['gid'] = (string)$data['gid']; |
| 128 | 128 | if (empty($data['gid'])) { |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @return $this |
| 146 | 146 | * @internal |
| 147 | 147 | */ |
| 148 | - protected function _setWithPost (string $path, array $data, string $field, $value = null) { |
|
| 148 | + protected function _setWithPost(string $path, array $data, string $field, $value = null) { |
|
| 149 | 149 | if ($this->hasGid()) { |
| 150 | 150 | /** @var array $remote */ |
| 151 | 151 | $remote = $this->api->post($path, $data, ['fields' => static::OPT_FIELDS[$field] ?? $field]); |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | /** |
| 162 | 162 | * @return null|string |
| 163 | 163 | */ |
| 164 | - final public function getGid (): ?string { |
|
| 164 | + final public function getGid(): ?string { |
|
| 165 | 165 | return $this->data['gid']; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @return string[] |
| 172 | 172 | */ |
| 173 | - public function getPoolKeys () { |
|
| 173 | + public function getPoolKeys() { |
|
| 174 | 174 | return [$this->getGid(), (string)$this]; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - final public function getResourceType (): string { |
|
| 182 | + final public function getResourceType(): string { |
|
| 183 | 183 | return $this::TYPE; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | 187 | * @return bool |
| 188 | 188 | */ |
| 189 | - final public function hasGid (): bool { |
|
| 189 | + final public function hasGid(): bool { |
|
| 190 | 190 | return isset($this->data['gid']); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @param string $field |
| 198 | 198 | * @return $this |
| 199 | 199 | */ |
| 200 | - public function reload (string $field = null) { |
|
| 200 | + public function reload(string $field = null) { |
|
| 201 | 201 | if (!$this->hasGid()) { // guards against loading a remote dir. |
| 202 | 202 | throw new LogicException(static::class . " has no GID, it can't be reloaded."); |
| 203 | 203 | } |
@@ -92,8 +92,7 @@ discard block |
||
| 92 | 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 | - } |
|
| 96 | - elseif (is_array($diff)) { |
|
| 95 | + } elseif (is_array($diff)) { |
|
| 97 | 96 | return $this->_set($field, array_values(array_diff($this->data[$field] ?? [], $diff))); |
| 98 | 97 | } |
| 99 | 98 | return $this->_set($field, array_values(array_filter($this->data[$field] ?? [], $diff))); |
@@ -109,11 +108,9 @@ discard block |
||
| 109 | 108 | protected function _save (string $dir = null) { |
| 110 | 109 | if (isset($dir)) { // create() |
| 111 | 110 | $remote = $this->api->post($dir, $this->getDiff(), ['expand' => 'this']); |
| 112 | - } |
|
| 113 | - elseif ($this->isDiff()) { // update() |
|
| 111 | + } elseif ($this->isDiff()) { // update() |
|
| 114 | 112 | $remote = $this->api->put($this, $this->getDiff(), ['expand' => 'this']); |
| 115 | - } |
|
| 116 | - else { // update() but no change |
|
| 113 | + } else { // update() but no change |
|
| 117 | 114 | return $this; |
| 118 | 115 | } |
| 119 | 116 | /** @var array $remote */ |
@@ -204,11 +201,9 @@ discard block |
||
| 204 | 201 | if (isset($field)) { |
| 205 | 202 | $remote = $this->api->get($this, [], ['fields' => static::OPT_FIELDS[$field] ?? $field]); |
| 206 | 203 | $this->_setMapped($field, $remote[$field] ?? null); |
| 207 | - } |
|
| 208 | - elseif ($remote = $this->api->get($this, [], ['expand' => 'this'])) { |
|
| 204 | + } elseif ($remote = $this->api->get($this, [], ['expand' => 'this'])) { |
|
| 209 | 205 | $this->_setData($remote); |
| 210 | - } |
|
| 211 | - else { // deleted upstream. |
|
| 206 | + } else { // deleted upstream. |
|
| 212 | 207 | $this->api->getPool()->remove($this->getPoolKeys()); |
| 213 | 208 | throw new RuntimeException("{$this} was deleted upstream."); |
| 214 | 209 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | 'custom_field' => CustomField::class, |
| 24 | 24 | ]; |
| 25 | 25 | |
| 26 | - protected function _setData (array $data): void { |
|
| 26 | + protected function _setData(array $data): void { |
|
| 27 | 27 | // these are the only fields that matter. |
| 28 | 28 | parent::_setData([ |
| 29 | 29 | 'custom_field' => $data['custom_field'], |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | ]); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - final public function getResourceType (): string { |
|
| 34 | + final public function getResourceType(): string { |
|
| 35 | 35 | return self::TYPE; |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @return CustomField[] |
| 17 | 17 | */ |
| 18 | - public function getCustomFields () { |
|
| 18 | + public function getCustomFields() { |
|
| 19 | 19 | return array_column($this->getCustomFieldSettings(), 'custom_field'); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | * @param callable $filter `fn( CustomField $field ): bool` |
| 24 | 24 | * @return CustomField[] |
| 25 | 25 | */ |
| 26 | - public function selectCustomFields (callable $filter) { |
|
| 26 | + public function selectCustomFields(callable $filter) { |
|
| 27 | 27 | return $this->{'_select'}($this->getCustomFields(), $filter); |
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | protected $types = []; |
| 55 | 55 | |
| 56 | - public function __construct (Task $task, array $data = []) { |
|
| 56 | + public function __construct(Task $task, array $data = []) { |
|
| 57 | 57 | $this->task = $task; |
| 58 | 58 | parent::__construct($task, $data); |
| 59 | 59 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param $offset |
| 63 | 63 | * @return null|string |
| 64 | 64 | */ |
| 65 | - protected function _toGid (string $offset) { |
|
| 65 | + protected function _toGid(string $offset) { |
|
| 66 | 66 | if (isset($this->names[$offset])) { |
| 67 | 67 | return $offset; |
| 68 | 68 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | /** |
| 73 | 73 | * @param array[] $values |
| 74 | 74 | */ |
| 75 | - protected function _setData (array $values): void { |
|
| 75 | + protected function _setData(array $values): void { |
|
| 76 | 76 | // ensure data is keyed by field gid |
| 77 | 77 | $values = array_combine(array_column($values, 'gid'), $values); |
| 78 | 78 | |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * @return int |
| 87 | 87 | */ |
| 88 | - public function count () { |
|
| 88 | + public function count() { |
|
| 89 | 89 | return count($this->data); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function getDiff (): array { |
|
| 92 | + public function getDiff(): array { |
|
| 93 | 93 | return array_map(function(FieldEntry $value) { |
| 94 | 94 | return $value->getValue(); |
| 95 | 95 | }, array_intersect_key($this->data, $this->diff)); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @param $fieldGid |
| 100 | 100 | * @return FieldEntry |
| 101 | 101 | */ |
| 102 | - public function getField ($fieldGid) { |
|
| 102 | + public function getField($fieldGid) { |
|
| 103 | 103 | return $this->data[$fieldGid]; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -107,41 +107,41 @@ discard block |
||
| 107 | 107 | * @param string $name |
| 108 | 108 | * @return string |
| 109 | 109 | */ |
| 110 | - public function getGid (string $name): string { |
|
| 110 | + public function getGid(string $name): string { |
|
| 111 | 111 | return $this->gids[$name]; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * @return string[] |
| 116 | 116 | */ |
| 117 | - public function getGids () { |
|
| 117 | + public function getGids() { |
|
| 118 | 118 | return $this->gids; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | 122 | * @return Generator |
| 123 | 123 | */ |
| 124 | - public function getIterator () { |
|
| 124 | + public function getIterator() { |
|
| 125 | 125 | foreach ($this->data as $gid => $field) { |
| 126 | 126 | yield $gid => $field->getValue(); |
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function getName (string $fieldGid) { |
|
| 130 | + public function getName(string $fieldGid) { |
|
| 131 | 131 | return $this->names[$fieldGid]; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * @return string[] |
| 136 | 136 | */ |
| 137 | - public function getNames () { |
|
| 137 | + public function getNames() { |
|
| 138 | 138 | return $this->names; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * @return array |
| 143 | 143 | */ |
| 144 | - public function getValues () { |
|
| 144 | + public function getValues() { |
|
| 145 | 145 | return iterator_to_array($this); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @param string $offset |
| 150 | 150 | * @return bool |
| 151 | 151 | */ |
| 152 | - public function offsetExists ($offset) { |
|
| 152 | + public function offsetExists($offset) { |
|
| 153 | 153 | return isset($this->data[$this->_toGid($offset)]); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @param string $offset |
| 158 | 158 | * @return null|number|string |
| 159 | 159 | */ |
| 160 | - public function offsetGet ($offset) { |
|
| 160 | + public function offsetGet($offset) { |
|
| 161 | 161 | return $this->data[$this->_toGid($offset)]->getValue(); |
| 162 | 162 | } |
| 163 | 163 | |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param string $offset |
| 166 | 166 | * @param null|number|string $value |
| 167 | 167 | */ |
| 168 | - public function offsetSet ($offset, $value) { |
|
| 168 | + public function offsetSet($offset, $value) { |
|
| 169 | 169 | $offset = $this->_toGid($offset); |
| 170 | 170 | $this->data[$offset]->setValue($value); |
| 171 | 171 | $this->diff[$offset] = true; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @param string $offset |
| 179 | 179 | */ |
| 180 | - public function offsetUnset ($offset) { |
|
| 180 | + public function offsetUnset($offset) { |
|
| 181 | 181 | $this->offsetSet($offset, null); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | * @param string $value |
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | - protected function _toEnumOptionGid (string $value): string { |
|
| 29 | + protected function _toEnumOptionGid(string $value): string { |
|
| 30 | 30 | return $this->getEnumOptionValues()[$value] ?? $value; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - public function getCurrentOptionName () { |
|
| 36 | + public function getCurrentOptionName() { |
|
| 37 | 37 | return $this->getEnumOptionNames()[$this->getValue()]; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return string[] |
| 44 | 44 | */ |
| 45 | - public function getEnumOptionNames () { |
|
| 45 | + public function getEnumOptionNames() { |
|
| 46 | 46 | static $names = []; // shared |
| 47 | 47 | $gid = $this->data['gid']; |
| 48 | 48 | return $names[$gid] ?? $names[$gid] = array_column($this->data['enum_options'], 'name', 'gid'); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return string[] |
| 55 | 55 | */ |
| 56 | - public function getEnumOptionValues () { |
|
| 56 | + public function getEnumOptionValues() { |
|
| 57 | 57 | static $values = []; // shared |
| 58 | 58 | $gid = $this->data['gid']; |
| 59 | 59 | return $values[$gid] ?? $values[$gid] = array_column($this->data['enum_options'], 'gid', 'name'); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | /** |
| 63 | 63 | * @return null|number|string |
| 64 | 64 | */ |
| 65 | - public function getValue () { |
|
| 65 | + public function getValue() { |
|
| 66 | 66 | $type = $this->data['type']; |
| 67 | 67 | if ($type === CustomField::TYPE_ENUM) { |
| 68 | 68 | return $this->data['enum_value']['gid'] ?? null; |
@@ -70,15 +70,15 @@ discard block |
||
| 70 | 70 | return $this->data["{$type}_value"]; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - final public function isEnum (): bool { |
|
| 73 | + final public function isEnum(): bool { |
|
| 74 | 74 | return $this->getType() === CustomField::TYPE_ENUM; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - final public function isNumber (): bool { |
|
| 77 | + final public function isNumber(): bool { |
|
| 78 | 78 | return $this->getType() === CustomField::TYPE_NUMBER; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - final public function isText (): bool { |
|
| 81 | + final public function isText(): bool { |
|
| 82 | 82 | return $this->getType() === CustomField::TYPE_TEXT; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @param null|number|string $value |
| 87 | 87 | * @return $this |
| 88 | 88 | */ |
| 89 | - public function setValue ($value) { |
|
| 89 | + public function setValue($value) { |
|
| 90 | 90 | $type = $this->data['type']; |
| 91 | 91 | $this->diff["{$type}_value"] = true; |
| 92 | 92 | if ($type === CustomField::TYPE_ENUM) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return array |
| 104 | 104 | */ |
| 105 | - public function toArray (): array { |
|
| 105 | + public function toArray(): array { |
|
| 106 | 106 | // only strip if needed. |
| 107 | 107 | if (!isset($this->data['resource_subtype'])) { |
| 108 | 108 | return $this->data; |