Skip to content

Commit 09fee32

Browse files
committed
qa: allow integer keys for some more methods
Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 25e2f73 commit 09fee32

File tree

2 files changed

+15
-101
lines changed

2 files changed

+15
-101
lines changed

psalm-baseline.xml

-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@
213213
</PossiblyInvalidPropertyAssignmentValue>
214214
<PossiblyUnusedMethod>
215215
<code><![CDATA[getCaching]]></code>
216-
<code><![CDATA[normalizeKey]]></code>
217-
<code><![CDATA[normalizeKeyValuePairs]]></code>
218216
<code><![CDATA[setCaching]]></code>
219217
</PossiblyUnusedMethod>
220218
<ReferenceConstraintViolation>

src/Storage/Adapter/AbstractAdapter.php

+15-99
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,6 @@ abstract protected function internalSetItem(string $normalizedKey, mixed $value)
593593

594594
/**
595595
* {@inheritDoc}
596-
*
597-
* @triggers setItems.pre(PreEvent)
598-
* @triggers setItems.post(PostEvent)
599-
* @triggers setItems.exception(ExceptionEvent)
600596
*/
601597
public function setItems(array $keyValuePairs): array
602598
{
@@ -630,15 +626,15 @@ public function setItems(array $keyValuePairs): array
630626
/**
631627
* Internal method to store multiple items.
632628
*
633-
* @param non-empty-array<non-empty-string,mixed> $normalizedKeyValuePairs
634-
* @return list<non-empty-string> Array of not stored keys
629+
* @param non-empty-array<non-empty-string|int,mixed> $normalizedKeyValuePairs
630+
* @return list<non-empty-string|int> Array of not stored keys
635631
* @throws Exception\ExceptionInterface
636632
*/
637633
protected function internalSetItems(array $normalizedKeyValuePairs): array
638634
{
639635
$failedKeys = [];
640636
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
641-
if (! $this->internalSetItem($normalizedKey, $value)) {
637+
if (! $this->internalSetItem((string) $normalizedKey, $value)) {
642638
$failedKeys[] = $normalizedKey;
643639
}
644640
}
@@ -647,12 +643,7 @@ protected function internalSetItems(array $normalizedKeyValuePairs): array
647643
}
648644

649645
/**
650-
* Add an item.
651-
*
652-
* @throws Exception\ExceptionInterface
653-
* @triggers addItem.pre(PreEvent)
654-
* @triggers addItem.post(PostEvent)
655-
* @triggers addItem.exception(ExceptionEvent)
646+
* {@inheritDoc}
656647
*/
657648
public function addItem(string $key, mixed $value): bool
658649
{
@@ -702,10 +693,6 @@ protected function internalAddItem(string $normalizedKey, mixed $value): bool
702693

703694
/**
704695
* {@inheritDoc}
705-
*
706-
* @triggers addItems.pre(PreEvent)
707-
* @triggers addItems.post(PostEvent)
708-
* @triggers addItems.exception(ExceptionEvent)
709696
*/
710697
public function addItems(array $keyValuePairs): array
711698
{
@@ -740,15 +727,15 @@ public function addItems(array $keyValuePairs): array
740727
/**
741728
* Internal method to add multiple items.
742729
*
743-
* @param non-empty-array<non-empty-string,mixed> $normalizedKeyValuePairs
744-
* @return list<non-empty-string> Array of not stored keys
730+
* @param non-empty-array<non-empty-string|int,mixed> $normalizedKeyValuePairs
731+
* @return list<non-empty-string|int> Array of not stored keys
745732
* @throws Exception\ExceptionInterface
746733
*/
747734
protected function internalAddItems(array $normalizedKeyValuePairs): array
748735
{
749736
$result = [];
750737
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
751-
if (! $this->internalAddItem($normalizedKey, $value)) {
738+
if (! $this->internalAddItem((string) $normalizedKey, $value)) {
752739
$result[] = $normalizedKey;
753740
}
754741
}
@@ -757,12 +744,7 @@ protected function internalAddItems(array $normalizedKeyValuePairs): array
757744
}
758745

759746
/**
760-
* Replace an existing item.
761-
*
762-
* @throws Exception\ExceptionInterface
763-
* @triggers replaceItem.pre(PreEvent)
764-
* @triggers replaceItem.post(PostEvent)
765-
* @triggers replaceItem.exception(ExceptionEvent)
747+
* {@inheritDoc}
766748
*/
767749
public function replaceItem(string $key, mixed $value): bool
768750
{
@@ -812,10 +794,6 @@ protected function internalReplaceItem(string $normalizedKey, mixed $value): boo
812794

813795
/**
814796
* {@inheritDoc}
815-
*
816-
* @triggers replaceItems.pre(PreEvent)
817-
* @triggers replaceItems.post(PostEvent)
818-
* @triggers replaceItems.exception(ExceptionEvent)
819797
*/
820798
public function replaceItems(array $keyValuePairs): array
821799
{
@@ -847,15 +825,15 @@ public function replaceItems(array $keyValuePairs): array
847825
/**
848826
* Internal method to replace multiple existing items.
849827
*
850-
* @param non-empty-array<non-empty-string,mixed> $normalizedKeyValuePairs
851-
* @return list<non-empty-string> Array of not stored keys
828+
* @param non-empty-array<non-empty-string|int,mixed> $normalizedKeyValuePairs
829+
* @return list<non-empty-string|int> Array of not stored keys
852830
* @throws Exception\ExceptionInterface
853831
*/
854832
protected function internalReplaceItems(array $normalizedKeyValuePairs): array
855833
{
856834
$result = [];
857835
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
858-
if (! $this->internalReplaceItem($normalizedKey, $value)) {
836+
if (! $this->internalReplaceItem((string) $normalizedKey, $value)) {
859837
$result[] = $normalizedKey;
860838
}
861839
}
@@ -864,15 +842,7 @@ protected function internalReplaceItems(array $normalizedKeyValuePairs): array
864842
}
865843

866844
/**
867-
* Set an item only if token matches
868-
*
869-
* It uses the token received from getItem() to check if the item has
870-
* changed before overwriting it.
871-
*
872-
* @see setItem()
873-
* @see getItem()
874-
*
875-
* @throws Exception\ExceptionInterface
845+
* {@inheritDoc}
876846
*/
877847
public function checkAndSetItem(mixed $token, string $key, mixed $value): bool
878848
{
@@ -906,9 +876,6 @@ public function checkAndSetItem(mixed $token, string $key, mixed $value): bool
906876
/**
907877
* Internal method to set an item only if token matches
908878
*
909-
* @see getItem()
910-
* @see setItem()
911-
*
912879
* @param non-empty-string $normalizedKey
913880
* @throws Exception\ExceptionInterface
914881
*/
@@ -923,12 +890,7 @@ protected function internalCheckAndSetItem(mixed $token, string $normalizedKey,
923890
}
924891

925892
/**
926-
* Reset lifetime of an item
927-
*
928-
* @throws Exception\ExceptionInterface
929-
* @triggers touchItem.pre(PreEvent)
930-
* @triggers touchItem.post(PostEvent)
931-
* @triggers touchItem.exception(ExceptionEvent)
893+
* {@inheritDoc}
932894
*/
933895
public function touchItem(string $key): bool
934896
{
@@ -976,10 +938,6 @@ protected function internalTouchItem(string $normalizedKey): bool
976938

977939
/**
978940
* {@inheritDoc}
979-
*
980-
* @triggers touchItems.pre(PreEvent)
981-
* @triggers touchItems.post(PostEvent)
982-
* @triggers touchItems.exception(ExceptionEvent)
983941
*/
984942
public function touchItems(array $keys): array
985943
{
@@ -1029,12 +987,7 @@ protected function internalTouchItems(array $normalizedKeys): array
1029987
}
1030988

1031989
/**
1032-
* Remove an item.
1033-
*
1034-
* @throws Exception\ExceptionInterface
1035-
* @triggers removeItem.pre(PreEvent)
1036-
* @triggers removeItem.post(PostEvent)
1037-
* @triggers removeItem.exception(ExceptionEvent)
990+
* {@inheritDoc}
1038991
*/
1039992
public function removeItem(string $key): bool
1040993
{
@@ -1076,10 +1029,6 @@ abstract protected function internalRemoveItem(string $normalizedKey): bool;
10761029

10771030
/**
10781031
* {@inheritDoc}
1079-
*
1080-
* @triggers removeItems.pre(PreEvent)
1081-
* @triggers removeItems.post(PostEvent)
1082-
* @triggers removeItems.exception(ExceptionEvent)
10831032
*/
10841033
public function removeItems(array $keys): array
10851034
{
@@ -1135,11 +1084,7 @@ protected function internalRemoveItems(array $normalizedKeys): array
11351084
/* status */
11361085

11371086
/**
1138-
* Get capabilities of this adapter
1139-
*
1140-
* @triggers getCapabilities.pre(PreEvent)
1141-
* @triggers getCapabilities.post(PostEvent)
1142-
* @triggers getCapabilities.exception(ExceptionEvent)
1087+
* {@inheritDoc}
11431088
*/
11441089
public function getCapabilities(): Capabilities
11451090
{
@@ -1172,21 +1117,6 @@ protected function internalGetCapabilities(): Capabilities
11721117
return $this->capabilities ??= new Capabilities();
11731118
}
11741119

1175-
/* internal */
1176-
1177-
/**
1178-
* Validates and normalizes a key
1179-
*
1180-
* @deprecated Use {@see AbstractAdapter::assertValidKey()} instead.
1181-
*
1182-
* @throws Exception\InvalidArgumentException On an invalid key.
1183-
* @psalm-assert non-empty-string $key
1184-
*/
1185-
protected function normalizeKey(string $key): void
1186-
{
1187-
$this->assertValidKey($key);
1188-
}
1189-
11901120
/**
11911121
* Validates and normalizes multiple keys
11921122
*
@@ -1203,20 +1133,6 @@ protected function normalizeKeys(array $keys): array
12031133
return array_values(array_unique($keys));
12041134
}
12051135

1206-
/**
1207-
* Validates and normalizes an array of key-value pairs
1208-
*
1209-
* @deprecated Please use {@see AbstractAdapter::assertValidKeyValuePairs()} instead.
1210-
*
1211-
* @param array<string,mixed> $keyValuePairs
1212-
* @psalm-assert array<non-empty-string,mixed> $keyValuePairs
1213-
* @throws Exception\InvalidArgumentException On an invalid key.
1214-
*/
1215-
protected function normalizeKeyValuePairs(array $keyValuePairs): void
1216-
{
1217-
$this->assertValidKeyValuePairs($keyValuePairs);
1218-
}
1219-
12201136
/**
12211137
* @template TKey
12221138
* @param TKey $key

0 commit comments

Comments
 (0)