Skip to content

Commit 82b6bce

Browse files
authored
Set ErrorLevel 1 for Psalm
1 parent 23a6e9f commit 82b6bce

12 files changed

Lines changed: 43 additions & 5 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"phpunit/phpunit": "^9.4",
2828
"roave/infection-static-analysis-plugin": "^1.5",
2929
"spatie/phpunit-watcher": "^1.23",
30-
"vimeo/psalm": "^4.3"
30+
"vimeo/psalm": "^4.7"
3131
},
3232
"provide": {
3333
"psr/simple-cache-implementation": "1.0.0"

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="2"
3+
errorLevel="1"
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ final class ArrayCache implements \Psr\SimpleCache\CacheInterface
2929
private const EXPIRATION_INFINITY = 0;
3030
private const EXPIRATION_EXPIRED = -1;
3131

32+
/** @psalm-var array<string, array{0: mixed, 1: int}> */
3233
private array $cache = [];
3334

3435
public function get($key, $default = null)
3536
{
3637
if ($this->has($key)) {
38+
/** @var mixed */
3739
$value = $this->cache[$key][0];
3840

3941
if (is_object($value)) {
@@ -83,7 +85,9 @@ public function getMultiple($keys, $default = null): iterable
8385
$results = [];
8486

8587
foreach ($keys as $key) {
88+
/** @var mixed */
8689
$value = $this->get($key, $default);
90+
/** @var mixed */
8791
$results[$key] = $value;
8892
}
8993

@@ -95,6 +99,7 @@ public function setMultiple($values, $ttl = null): bool
9599
$values = $this->iterableToArray($values);
96100
$this->validateKeysOfValues($values);
97101

102+
/** @var mixed */
98103
foreach ($values as $key => $value) {
99104
$this->set((string) $key, $value, $ttl);
100105
}
@@ -203,9 +208,11 @@ private function validateKey($key): void
203208

204209
/**
205210
* @param array $keys
211+
* @psalm-assert string[] $keys
206212
*/
207213
private function validateKeys(array $keys): void
208214
{
215+
/** @var mixed $key */
209216
foreach ($keys as $key) {
210217
$this->validateKey($key);
211218
}

src/Cache.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function psr(): \Psr\SimpleCache\CacheInterface
7070
public function getOrSet($key, callable $callable, $ttl = null, Dependency $dependency = null, float $beta = 1.0)
7171
{
7272
$key = $this->keyNormalizer->normalize($key);
73+
/** @var mixed */
7374
$value = $this->getValue($key, $beta);
7475

7576
return $value ?? $this->setAndGet($key, $callable, $ttl, $dependency);
@@ -100,6 +101,7 @@ private function getValue(string $key, float $beta)
100101
return null;
101102
}
102103

104+
/** @var mixed */
103105
$value = $this->psr->getRaw($key);
104106

105107
if (is_array($value) && isset($value[1]) && $value[1] instanceof CacheItem) {
@@ -120,6 +122,8 @@ private function getValue(string $key, float $beta)
120122
*
121123
* @param string $key The unique key of this item in the cache.
122124
* @param callable $callable The callable or closure that will be used to generate a value to be cached.
125+
* @psalm-param callable(\Psr\SimpleCache\CacheInterface): mixed $callable
126+
*
123127
* @param DateInterval|int|null $ttl The TTL of this value. If not set, default value is used.
124128
* @param Dependency|null $dependency The dependency of the cache value.
125129
*
@@ -132,6 +136,7 @@ private function setAndGet(string $key, callable $callable, $ttl, ?Dependency $d
132136
{
133137
$ttl = $this->normalizeTtl($ttl);
134138
$ttl ??= $this->defaultTtl;
139+
/** @var mixed */
135140
$value = $callable($this->psr);
136141

137142
if ($dependency !== null) {

src/CacheInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function psr(): \Psr\SimpleCache\CacheInterface;
4242
*
4343
* @param mixed $key The key identifying the value to be cached.
4444
* @param callable $callable The callable or closure that will be used to generate a value to be cached.
45+
* @psalm-param callable(\Psr\SimpleCache\CacheInterface): mixed $callable
46+
*
4547
* @param DateInterval|int|null $ttl The TTL of this value. If not set, default value is used.
4648
* @param Dependency|null $dependency The dependency of the cache value. If the dependency
4749
* changes, the corresponding value in the cache will be invalidated when it is fetched.

src/Dependency/AllDependencies.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ final class AllDependencies extends Dependency
2525
private array $dependencies;
2626

2727
/**
28-
* @param array $dependencies list of dependencies that this dependency is composed of.
28+
* @param Dependency[] $dependencies list of dependencies that this dependency is composed of.
2929
* Each array element must be a dependency object.
3030
*/
3131
public function __construct(array $dependencies = [])
3232
{
3333
foreach ($dependencies as $dependency) {
34+
/** @psalm-suppress DocblockTypeContradiction */
3435
if (!($dependency instanceof Dependency)) {
3536
throw new InvalidArgumentException(sprintf(
3637
'The dependency must be a "%s" instance, "%s" received',

src/Dependency/AnyDependency.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ final class AnyDependency extends Dependency
2525
private array $dependencies;
2626

2727
/**
28-
* @param array $dependencies List of dependencies that this dependency is composed of.
28+
* @param Dependency[] $dependencies List of dependencies that this dependency is composed of.
2929
* Each array element must be a dependency object.
3030
*/
3131
public function __construct(array $dependencies = [])
3232
{
3333
foreach ($dependencies as $dependency) {
34+
/** @psalm-suppress DocblockTypeContradiction */
3435
if (!($dependency instanceof Dependency)) {
3536
throw new InvalidArgumentException(sprintf(
3637
'The dependency must be a "%s" instance, "%s" received',

src/Dependency/Dependency.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ abstract class Dependency
3535

3636
/**
3737
* @var array Static storage of cached data for reusable dependencies.
38+
* @psalm-var array<string, mixed>
3839
*/
3940
private static array $reusableData = [];
4041

@@ -65,6 +66,7 @@ public function evaluateDependency(CacheInterface $cache): void
6566
$hash = $this->generateReusableHash();
6667

6768
if (!array_key_exists($hash, self::$reusableData)) {
69+
/** @var mixed */
6870
self::$reusableData[$hash] = $this->generateDependencyData($cache);
6971
}
7072

@@ -87,6 +89,7 @@ public function isChanged(CacheInterface $cache): bool
8789
$hash = $this->generateReusableHash();
8890

8991
if (!array_key_exists($hash, self::$reusableData)) {
92+
/** @var mixed */
9093
self::$reusableData[$hash] = $this->generateDependencyData($cache);
9194
}
9295

@@ -110,6 +113,7 @@ public static function resetReusableData(): void
110113
*/
111114
protected function generateReusableHash(): string
112115
{
116+
/** @var mixed */
113117
$data = $this->data;
114118
$this->data = null; // https://github.com/yiisoft/yii2/issues/3052
115119
$key = sha1(serialize($this));

src/Dependency/TagDependency.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ private static function buildCacheKeys($tags): array
128128
{
129129
$keys = [];
130130

131+
/** @var mixed $tag */
131132
foreach ((array) $tags as $tag) {
132133
$keys[] = self::buildCacheKey((string) $tag);
133134
}
@@ -141,9 +142,11 @@ private static function buildCacheKeys($tags): array
141142
* @param CacheInterface $cache
142143
*
143144
* @return array
145+
* @psalm-return array<array-key, string|null>
144146
*/
145147
private function getTagsData(CacheInterface $cache): array
146148
{
149+
/** @psalm-var array<array-key, string|null> */
147150
return $this->iterableToArray($cache->psr()->getMultiple(self::buildCacheKeys($this->tags)));
148151
}
149152
}

src/DependencyAwareCache.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class DependencyAwareCache implements PsrSimpleCacheInterface
2828
private PsrSimpleCacheInterface $handler;
2929

3030
/**
31-
* @param CacheInterface $cache The actual cache handler.
31+
* @param CacheInterface $cache The actual cache.
3232
* @param PsrSimpleCacheInterface $handler The actual cache handler.
3333
*/
3434
public function __construct(CacheInterface $cache, PsrSimpleCacheInterface $handler)
@@ -39,6 +39,7 @@ public function __construct(CacheInterface $cache, PsrSimpleCacheInterface $hand
3939

4040
public function get($key, $default = null)
4141
{
42+
/** @var mixed */
4243
$value = $this->handler->get($key, $default);
4344
return $this->checkAndGetValue($key, $value, $default);
4445
}
@@ -62,7 +63,12 @@ public function getMultiple($keys, $default = null): iterable
6263
{
6364
$values = [];
6465

66+
/**
67+
* @var string $key
68+
* @var mixed $value
69+
*/
6570
foreach ($this->handler->getMultiple($keys, $default) as $key => $value) {
71+
/** @var mixed */
6672
$values[$key] = $this->checkAndGetValue($key, $value, $default);
6773
}
6874

0 commit comments

Comments
 (0)