Skip to content

Commit ab102cc

Browse files
authored
Lower ErrorLevel for Psalm, fix issues (#73)
1 parent ffae890 commit ab102cc

12 files changed

Lines changed: 34 additions & 28 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"phpunit/phpunit": "^9.4",
2929
"roave/infection-static-analysis-plugin": "^1.5",
3030
"spatie/phpunit-watcher": "^1.23",
31-
"vimeo/psalm": "^4.2"
31+
"vimeo/psalm": "^4.3"
3232
},
3333
"suggest": {
3434
"yiisoft/cache-wincache": "To store cache using WinCache PECL extension",

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="6"
3+
errorLevel="2"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

src/ArrayCache.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ final class ArrayCache implements CacheInterface
2121

2222
private array $cache = [];
2323

24+
/**
25+
* @param string $key
26+
* @param mixed $default
27+
*
28+
* @return mixed|null
29+
*/
2430
public function get($key, $default = null)
2531
{
2632
$this->validateKey($key);
2733
if (isset($this->cache[$key]) && !$this->isExpired($key)) {
34+
/** @var mixed */
2835
$value = $this->cache[$key][0];
2936
if (is_object($value)) {
3037
$value = clone $value;
@@ -145,7 +152,6 @@ private function ttlToExpiration($ttl): int
145152
* @param DateInterval|int|string|null $ttl raw TTL.
146153
*
147154
* @return int|null TTL value as UNIX timestamp or null meaning infinity
148-
* @suppress PhanPossiblyFalseTypeReturn
149155
*/
150156
private function normalizeTtl($ttl): ?int
151157
{
@@ -163,21 +169,23 @@ private function normalizeTtl($ttl): ?int
163169
/**
164170
* Converts iterable to array. If provided value is not iterable it throws an InvalidArgumentException
165171
*
166-
* @param $iterable
172+
* @param iterable $iterable
167173
*
168174
* @return array
169175
*/
170176
private function iterableToArray($iterable): array
171177
{
178+
/** @psalm-suppress DocblockTypeContradiction */
172179
if (!is_iterable($iterable)) {
173180
throw new InvalidArgumentException('Iterable is expected, got ' . gettype($iterable));
174181
}
175182

183+
/** @psalm-suppress RedundantCast */
176184
return $iterable instanceof \Traversable ? iterator_to_array($iterable) : (array)$iterable;
177185
}
178186

179187
/**
180-
* @param $key
188+
* @param mixed $key
181189
*/
182190
private function validateKey($key): void
183191
{

src/Cache.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function set($key, $value, $ttl = null, Dependency $dependency = null): b
143143
* If the cache already contains such a key, the existing value and
144144
* expiration time will be replaced with the new ones, respectively.
145145
*
146-
* @param array $values the values to be cached, as key-value pairs.
146+
* @param iterable $values the values to be cached, as key-value pairs.
147147
* @param \DateInterval|int|null $ttl the TTL value of this value. If not set, default value is used.
148148
* @param Dependency|null $dependency dependency of the cached values. If the dependency changes,
149149
* the corresponding values in the cache will be invalidated when it is fetched via {@see CacheInterface::get()}.
@@ -362,6 +362,7 @@ protected function normalizeTtl($ttl): ?int
362362
*/
363363
private function iterableToArray(iterable $iterable): array
364364
{
365+
/** @psalm-suppress RedundantCast */
365366
return $iterable instanceof \Traversable ? iterator_to_array($iterable) : (array)$iterable;
366367
}
367368

src/Dependency/AllDependencies.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AllDependencies extends Dependency
1616
/**
1717
* @var Dependency[]
1818
*/
19-
private $dependencies;
19+
private array $dependencies;
2020

2121
/**
2222
* @param Dependency[] $dependencies list of dependencies that this dependency is composed of.
@@ -38,7 +38,6 @@ public function evaluateDependency(CacheInterface $cache): void
3838
* @codeCoverageIgnore method is not used
3939
*
4040
* @param CacheInterface $cache
41-
* @suppress PhanUnusedProtectedMethodParameter
4241
*/
4342
protected function generateDependencyData(CacheInterface $cache)
4443
{

src/Dependency/AnyDependency.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AnyDependency extends Dependency
1616
/**
1717
* @var Dependency[]
1818
*/
19-
private $dependencies;
19+
private array $dependencies;
2020

2121
/**
2222
* @param Dependency[] $dependencies list of dependencies that this dependency is composed of.
@@ -38,7 +38,6 @@ public function evaluateDependency(CacheInterface $cache): void
3838
* @codeCoverageIgnore method is not used
3939
*
4040
* @param CacheInterface $cache
41-
* @suppress PhanUnusedProtectedMethodParameter
4241
*/
4342
protected function generateDependencyData(CacheInterface $cache)
4443
{

src/Dependency/CallbackDependency.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function __construct(callable $callback)
2525
* @param CacheInterface $cache
2626
*
2727
* @return mixed
28-
* @suppress PhanUnusedProtectedMethodParameter
2928
*/
3029
protected function generateDependencyData(CacheInterface $cache)
3130
{

src/Dependency/Dependency.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ abstract class Dependency
2626
* to use the same cache dependency for multiple separate cache calls while generating the same
2727
* page without an overhead of re-evaluating dependency data each time. Defaults to false.
2828
*/
29-
protected $isReusable = false;
29+
protected bool $isReusable = false;
3030

3131
/**
3232
* @var array static storage of cached data for reusable dependencies.
3333
*/
34-
private static $reusableData = [];
34+
private static array $reusableData = [];
3535

3636
/**
3737
* Changes dependency behavior so dependent data for this cache dependency will be generated only once per request.
@@ -117,6 +117,7 @@ protected function generateReusableHash(): string
117117
*/
118118
protected function iterableToArray(iterable $iterable): array
119119
{
120+
/** @psalm-suppress RedundantCast */
120121
return $iterable instanceof \Traversable ? iterator_to_array($iterable) : (array)$iterable;
121122
}
122123

src/Dependency/FileDependency.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
final class FileDependency extends Dependency
1616
{
17-
private $fileName;
17+
private string $fileName;
1818

1919
/**
2020
* @param string $fileName the file path whose last modification time is used to
@@ -29,8 +29,6 @@ public function __construct(string $fileName)
2929
* @param CacheInterface $cache
3030
*
3131
* @return false|int|mixed
32-
* @suppress PhanUnusedProtectedMethodParameter
33-
* @suppress PhanUnusedProtectedFinalMethodParameter
3432
*/
3533
protected function generateDependencyData(CacheInterface $cache)
3634
{

src/Dependency/TagDependency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class TagDependency extends Dependency
2626
/**
2727
* @var array a list of tag names for this dependency
2828
*/
29-
private $tags;
29+
private array $tags;
3030

3131
/**
3232
* @param array|string $tags a list of tag names for this dependency. For a single tag, you may specify it as a string

0 commit comments

Comments
 (0)