Skip to content

Commit 0f993b7

Browse files
committed
feature: allow integer keys in iterables as per PSR integration tests
In the (non-official) PSR integration tests are checks for iterables with a non-empty-string cache key `0`. Internal PHP type juggling converts integerish strings to `int` which leads to a type conflict when passing these values to our internal assertion. Therefore, this patch provides compatibility for integer keys in methods consuming iterable keys either in key-value or key-only combination. Signed-off-by: Maximilian Bösing <[email protected]>
1 parent ba823c8 commit 0f993b7

12 files changed

+113
-155
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"laminas/laminas-config-aggregator": "^1.13",
5050
"laminas/laminas-serializer": "^3.0",
5151
"phpunit/phpunit": "^9.5.27",
52-
"psalm/plugin-phpunit": "^0.18.4",
53-
"vimeo/psalm": "^5.4"
52+
"psalm/plugin-phpunit": "^0.19.0",
53+
"vimeo/psalm": "^5.24"
5454
},
5555
"conflict": {
5656
"laminas/laminas-serializer": "<3.0",

composer.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm-baseline.xml

+1-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.22.2@d768d914152dbbf3486c36398802f74e80cfde48">
2+
<files psalm-version="5.24.0@462c80e31c34e58cc4f750c656be3927e80e550e">
33
<file src="src/Exception/BadMethodCallException.php">
44
<UnusedClass>
55
<code><![CDATA[BadMethodCallException]]></code>
@@ -119,11 +119,6 @@
119119
<code><![CDATA[setUmask]]></code>
120120
</PossiblyUnusedMethod>
121121
</file>
122-
<file src="src/Psr/SimpleCache/SimpleCacheDecorator.php">
123-
<InvalidArgument>
124-
<code><![CDATA[$values]]></code>
125-
</InvalidArgument>
126-
</file>
127122
<file src="src/Service/StorageAdapterFactory.php">
128123
<InvalidArgument>
129124
<code><![CDATA[$pluginConfiguration]]></code>
@@ -460,10 +455,6 @@
460455
<code><![CDATA[testSetShouldRaisePsrInvalidArgumentExceptionForInvalidKeys]]></code>
461456
<code><![CDATA[testSetShouldRemoveItemFromCacheIfTtlIsBelow1]]></code>
462457
</MissingReturnType>
463-
<MixedInferredReturnType>
464-
<code><![CDATA[array]]></code>
465-
<code><![CDATA[array]]></code>
466-
</MixedInferredReturnType>
467458
</file>
468459
<file src="test/Service/StorageAdapterFactoryFactoryTest.php">
469460
<DeprecatedMethod>
@@ -499,43 +490,13 @@
499490
<MixedMethodCall>
500491
<code><![CDATA[getResult]]></code>
501492
</MixedMethodCall>
502-
<PossiblyNullReference>
503-
<code><![CDATA[getNamespace]]></code>
504-
<code><![CDATA[setKeyPattern]]></code>
505-
<code><![CDATA[setKeyPattern]]></code>
506-
<code><![CDATA[setKeyPattern]]></code>
507-
<code><![CDATA[setNamespace]]></code>
508-
<code><![CDATA[setNamespace]]></code>
509-
<code><![CDATA[setReadable]]></code>
510-
<code><![CDATA[setTtl]]></code>
511-
<code><![CDATA[setTtl]]></code>
512-
<code><![CDATA[setWritable]]></code>
513-
</PossiblyNullReference>
514493
<PossiblyUndefinedVariable>
515494
<code><![CDATA[$success]]></code>
516495
</PossiblyUndefinedVariable>
517496
<PossiblyUnusedMethod>
518497
<code><![CDATA[simpleEventHandlingMethodDefinitions]]></code>
519498
</PossiblyUnusedMethod>
520499
</file>
521-
<file src="test/Storage/Adapter/AdapterOptionsTest.php">
522-
<PossiblyNullReference>
523-
<code><![CDATA[getKeyPattern]]></code>
524-
<code><![CDATA[getTtl]]></code>
525-
<code><![CDATA[setAdapter]]></code>
526-
<code><![CDATA[setFromArray]]></code>
527-
<code><![CDATA[setKeyPattern]]></code>
528-
<code><![CDATA[setKeyPattern]]></code>
529-
<code><![CDATA[setNamespace]]></code>
530-
<code><![CDATA[setReadable]]></code>
531-
<code><![CDATA[setTtl]]></code>
532-
<code><![CDATA[setTtl]]></code>
533-
<code><![CDATA[setWritable]]></code>
534-
</PossiblyNullReference>
535-
<PossiblyUnusedProperty>
536-
<code><![CDATA[$storage]]></code>
537-
</PossiblyUnusedProperty>
538-
</file>
539500
<file src="test/Storage/Adapter/TestAsset/AdapterWithStorageAndEventsCapableInterface.php">
540501
<MissingReturnType>
541502
<code><![CDATA[addPlugin]]></code>

src/Psr/CacheItemPool/CacheItemPoolDecorator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function getItems(array $keys = []): array
129129
}
130130

131131
foreach ($cacheItems as $key => $value) {
132-
$items[$key] = new CacheItem($key, $value, true, $this->clock);
132+
$items[$key] = new CacheItem((string) $key, $value, true, $this->clock);
133133
}
134134

135135
// Return empty items for any keys that where not found

src/Psr/SimpleCache/SimpleCacheDecorator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function setMultiple(iterable $values, int|DateInterval|null $ttl = null)
247247
}
248248

249249
foreach ($result as $index => $key) {
250-
if (! $this->storage->hasItem($key)) {
250+
if (! $this->storage->hasItem((string) $key)) {
251251
unset($result[$index]);
252252
}
253253
}
@@ -276,7 +276,7 @@ public function deleteMultiple(iterable $keys): bool
276276
}
277277

278278
foreach ($result as $index => $key) {
279-
if (! $this->storage->hasItem($key)) {
279+
if (! $this->storage->hasItem((string) $key)) {
280280
unset($result[$index]);
281281
}
282282
}

src/Storage/AbstractMetadataCapableAdapter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ public function getMetadatas(array $keys): array
132132
/**
133133
* Internal method to get multiple metadata
134134
*
135-
* @param array<string> $normalizedKeys
136-
* @return array<string,TMetadata> Associative array of keys and metadata
135+
* @param array<non-empty-string|int> $normalizedKeys
136+
* @return array<non-empty-string|int,TMetadata> Associative array of keys and metadata
137137
* @throws ExceptionInterface
138138
*/
139139
protected function internalGetMetadatas(array $normalizedKeys): array
140140
{
141141
$result = [];
142142
foreach ($normalizedKeys as $normalizedKey) {
143-
$metadata = $this->internalGetMetadata($normalizedKey);
143+
$metadata = $this->internalGetMetadata((string) $normalizedKey);
144144
if ($metadata === null) {
145145
continue;
146146
}

0 commit comments

Comments
 (0)