@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * @param PSR16 $psr |
| 35 | 35 | */ |
| 36 | - public function __construct (PSR16 $psr) { |
|
| 36 | + public function __construct(PSR16 $psr) { |
|
| 37 | 37 | $this->psr = $psr; |
| 38 | 38 | } |
| 39 | 39 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param AbstractEntity $entity |
| 42 | 42 | * @throws CacheException |
| 43 | 43 | */ |
| 44 | - protected function _add (AbstractEntity $entity): void { |
|
| 44 | + protected function _add(AbstractEntity $entity): void { |
|
| 45 | 45 | $this->psr->set("asana/{$entity->getGid()}", $entity, $this->_getTtl($entity)); |
| 46 | 46 | parent::_add($entity); |
| 47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param string[] $keys |
| 52 | 52 | * @throws CacheException |
| 53 | 53 | */ |
| 54 | - protected function _addKeys (AbstractEntity $entity, ...$keys): void { |
|
| 54 | + protected function _addKeys(AbstractEntity $entity, ...$keys): void { |
|
| 55 | 55 | $gid = $entity->getGid(); |
| 56 | 56 | $ttl = $this->_getTtl($entity); |
| 57 | 57 | foreach ($keys as $key) { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return null|AbstractEntity |
| 69 | 69 | * @throws CacheException |
| 70 | 70 | */ |
| 71 | - protected function _get (string $key, $caller) { |
|
| 71 | + protected function _get(string $key, $caller) { |
|
| 72 | 72 | if (!$entity = parent::_get($key, $caller) and $entity = $this->psr->get("asana/{$key}")) { |
| 73 | 73 | if (is_string($entity)) { // gid ref |
| 74 | 74 | if (!$entity = $this->_get($entity, $caller)) { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | return $entity; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - protected function _getTtl (AbstractEntity $entity): int { |
|
| 86 | + protected function _getTtl(AbstractEntity $entity): int { |
|
| 87 | 87 | if ($entity instanceof ImmutableInterface) { |
| 88 | 88 | return strtotime('tomorrow') - time(); |
| 89 | 89 | } |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | * @return bool |
| 96 | 96 | * @throws CacheException |
| 97 | 97 | */ |
| 98 | - protected function _has (string $key): bool { |
|
| 98 | + protected function _has(string $key): bool { |
|
| 99 | 99 | return parent::_has($key) or $this->psr->has("asana/{$key}"); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * @return int |
| 104 | 104 | */ |
| 105 | - public function getTtl (): int { |
|
| 105 | + public function getTtl(): int { |
|
| 106 | 106 | return $this->ttl; |
| 107 | 107 | } |
| 108 | 108 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string[] $keys |
| 111 | 111 | * @throws CacheException |
| 112 | 112 | */ |
| 113 | - public function remove (array $keys): void { |
|
| 113 | + public function remove(array $keys): void { |
|
| 114 | 114 | parent::remove($keys); |
| 115 | 115 | foreach ($keys as $key) { |
| 116 | 116 | $this->psr->delete("asana/{$key}"); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param int $ttl |
| 122 | 122 | * @return $this |
| 123 | 123 | */ |
| 124 | - public function setTtl (int $ttl) { |
|
| 124 | + public function setTtl(int $ttl) { |
|
| 125 | 125 | $this->ttl = $ttl; |
| 126 | 126 | return $this; |
| 127 | 127 | } |
@@ -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 "{$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 mixed $default Unused. |
| 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 |
@@ -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_string($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 $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 |