diff --git a/.phpstan.neon b/.phpstan.neon deleted file mode 100644 index 50e0daa..0000000 --- a/.phpstan.neon +++ /dev/null @@ -1,7 +0,0 @@ -parameters: - ignoreErrors: - # Ignore documentElement errors: - - '# on DOMElement|null#' - -includes: -- vendor/phpstan/phpstan-phpunit/extension.neon \ No newline at end of file diff --git a/composer.json b/composer.json index 2798861..fc80ec5 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "ext-xsl" : "*", "ext-dom" : "*", "ext-intl" : "*", - "psr/simple-cache": "^1.0" + "psr/simple-cache": "^3.0" }, "require-dev" : { "phpunit/phpunit": "^9", @@ -25,5 +25,13 @@ "psr-4" : { "Genkgo\\Xsl\\" : ["test"] } + }, + "scripts": { + "test": [ + "./vendor/bin/phpunit -c phpunit.xml", + "./vendor/bin/phpstan analyse -l 5 src", + "./vendor/bin/phpstan analyse -l 7 test", + "./vendor/bin/php-cs-fixer fix --dry-run --verbose --config .php-cs-fixer.dist.php ./src ./test" + ] } } diff --git a/src/Cache/ArrayCache.php b/src/Cache/ArrayCache.php index 382c2b3..05c0dd2 100644 --- a/src/Cache/ArrayCache.php +++ b/src/Cache/ArrayCache.php @@ -7,17 +7,9 @@ final class ArrayCache implements CacheInterface { - /** - * @var array - */ - private $memory = []; - - /** - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get($key, $default = null) + private array $memory = []; + + public function get(string $key, mixed $default = null): mixed { if (isset($this->memory[$key])) { return $this->getNonExpiredCacheOrDefault($this->memory[$key], $default); @@ -26,13 +18,7 @@ public function get($key, $default = null) return $default; } - /** - * @param string $key - * @param mixed $value - * @param int|null|\DateInterval $ttl - * @return bool - */ - public function set($key, $value, $ttl = null) + public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool { $expires = null; @@ -47,43 +33,26 @@ public function set($key, $value, $ttl = null) return true; } - /** - * @param string $key - * @return bool - */ - public function delete($key) + public function delete(string $key): bool { unset($this->memory[$key]); return true; } - /** - * @return bool - */ - public function clear() + public function clear(): bool { $this->memory = []; return true; } - /** - * @param iterable $keys - * @param mixed $default - * @return iterable - */ - public function getMultiple($keys, $default = null) + public function getMultiple(iterable $keys, mixed $default = null): iterable { - foreach (\array_keys($this->memory) as $key) { - yield $this->get($key, $default); + foreach ($keys as $key) { + yield $key => $this->get($key, $default); } } - /** - * @param iterable $values - * @param null|int|\DateInterval $ttl - * @return bool - */ - public function setMultiple($values, $ttl = null) + public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { foreach ($values as $key => $value) { $this->set($key, $value, $ttl); @@ -92,11 +61,7 @@ public function setMultiple($values, $ttl = null) return true; } - /** - * @param iterable $keys - * @return bool - */ - public function deleteMultiple($keys) + public function deleteMultiple(iterable $keys): bool { foreach (\array_keys($this->memory) as $key) { $this->delete($key); @@ -105,21 +70,12 @@ public function deleteMultiple($keys) return true; } - /** - * @param string $key - * @return bool - */ - public function has($key) + public function has(string $key): bool { return isset($this->memory[$key]); } - /** - * @param array $keyData - * @param mixed|null $default - * @return mixed - */ - private function getNonExpiredCacheOrDefault(array $keyData, $default = null) + private function getNonExpiredCacheOrDefault(array $keyData, mixed $default = null): mixed { [$value, $expires] = $keyData; diff --git a/src/Cache/NullCache.php b/src/Cache/NullCache.php index fa88b85..94919b4 100644 --- a/src/Cache/NullCache.php +++ b/src/Cache/NullCache.php @@ -7,78 +7,42 @@ final class NullCache implements CacheInterface { - /** - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get($key, $default = null) + public function get(string $key, mixed $default = null): mixed { return $default; } - /** - * @param string $key - * @param mixed $value - * @param int|null $ttl - * @return bool - */ - public function set($key, $value, $ttl = null) + public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool { return true; } - /** - * @param string $key - * @return bool - */ - public function delete($key) + public function delete(string $key): bool { return true; } - /** - * @return bool - */ - public function clear() + public function clear(): bool { return true; } - /** - * @param iterable $keys - * @param mixed $default - * @return iterable - */ - public function getMultiple($keys, $default = null) + public function getMultiple(iterable $keys, mixed $default = null): iterable { return []; } - /** - * @param iterable $values - * @param null|int|\DateInterval $ttl - * @return bool - */ - public function setMultiple($values, $ttl = null) + public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { return true; } - /** - * @param iterable $keys - * @return bool - */ - public function deleteMultiple($keys) + public function deleteMultiple(iterable $keys): bool { return true; } - /** - * @param string $key - * @return bool - */ - public function has($key) + public function has(string $key): bool { return false; }