Skip to content

Commit 8e5038f

Browse files
committed
Fixed multiple type issues revealed in #862
1 parent 384b6fc commit 8e5038f

File tree

15 files changed

+24
-16
lines changed

15 files changed

+24
-16
lines changed

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,6 @@ protected function encode($data): string
269269
*/
270270
protected function decode(?string $value): mixed
271271
{
272-
return \unserialize((string) $value, ['allowed_classes' => true]);
272+
return $value ? \unserialize($value, ['allowed_classes' => true]) : null;
273273
}
274274
}

lib/Phpfastcache/Drivers/Apcu/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
9292
{
9393
$data = apcu_fetch($item->getKey(), $success);
9494

95-
if ($success === false) {
95+
if ($success === false || !\is_array($data)) {
9696
return null;
9797
}
9898

lib/Phpfastcache/Drivers/Arangodb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
131131
return null;
132132
}
133133
throw new PhpfastcacheDriverException(
134-
'Got unexpeced error from Arangodb: ' . $e->getMessage()
134+
'Got unexpected error from Arangodb: ' . $e->getMessage()
135135
);
136136
}
137137

lib/Phpfastcache/Drivers/Cassandra/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
140140
$results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options);
141141

142142
if ($results instanceof Cassandra\Rows && $results->count() === 1) {
143-
return $this->decode($results->first()['cache_data']);
143+
return $this->decode($results->first()['cache_data']) ?: null;
144144
}
145145

146146
return null;

lib/Phpfastcache/Drivers/Couchdb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected function encodeDocument(array $data): array
257257
* @return mixed
258258
* @throws \Exception
259259
*/
260-
protected function decode($value): mixed
260+
protected function decode($value): array
261261
{
262262
$value[ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX] = \unserialize(
263263
$value[ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX],

lib/Phpfastcache/Drivers/Files/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
7171
return null;
7272
}
7373

74-
return $this->decode($content) ?: null;
74+
return $this->decode($content);
7575
}
7676

7777
/**

lib/Phpfastcache/Drivers/Memcache/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
149149
{
150150
$val = $this->instance->get($item->getKey());
151151

152-
if ($val === false) {
152+
if (empty($val) || !\is_array($val)) {
153153
return null;
154154
}
155155

lib/Phpfastcache/Drivers/Memcached/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
147147
{
148148
$val = $this->instance->get($item->getKey());
149149

150-
if ($val === false) {
150+
if (empty($val) || !\is_array($val)) {
151151
return null;
152152
}
153153

lib/Phpfastcache/Drivers/Predis/Driver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ protected function driverConnect(): bool
143143
protected function driverRead(ExtendedCacheItemInterface $item): ?array
144144
{
145145
$val = $this->instance->get($item->getKey());
146-
if ($val == false) {
146+
147+
if ($val === null) {
147148
return null;
148149
}
149150

lib/Phpfastcache/Drivers/Ssdb/Driver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ protected function driverConnect(): bool
9494
protected function driverRead(ExtendedCacheItemInterface $item): ?array
9595
{
9696
$val = $this->instance->get($item->getEncodedKey());
97-
if (!$val) {
97+
98+
if (empty($val)) {
9899
return null;
99100
}
100101

0 commit comments

Comments
 (0)