Skip to content

Commit 1263af4

Browse files
committed
Make codestyle happy
Signed-off-by: Sven Rautenberg <sven@rtbg.de>
1 parent 523e13c commit 1263af4

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@
393393
</PossiblyUnusedMethod>
394394
<PossiblyUnusedProperty>
395395
<code><![CDATA[$property]]></code>
396+
<code><![CDATA[$closure]]></code>
396397
</PossiblyUnusedProperty>
397398
</file>
398399
<file src="test/Psr/CacheItemPool/CacheItemPoolDecoratorTest.php">

src/Pattern/CallbackCache.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use function array_key_exists;
99
use function array_values;
10+
use function is_array;
1011
use function is_callable;
1112
use function is_object;
1213
use function md5;
@@ -111,19 +112,18 @@ public function generateKey(callable $callback, array $args = []): string
111112
*/
112113
protected function generateCallbackKey(callable $callback, array $args): string
113114
{
115+
if (! is_callable($callback, false, $callbackKey)) {
116+
throw new Exception\InvalidArgumentException('Invalid callback');
117+
}
114118

115119
// Create a cache key for the ObjectCache use case.
116120
$options = $this->getOptions();
117-
if (is_object($options->getObject())) {
121+
if (is_object($options->getObject()) && is_array($callback) && isset($callback[1])) {
118122
$callbackKey = md5($options->getObjectKey() . '::' . strtolower($callback[1]));
119123
$argumentKey = $this->generateArgumentsKey($args);
120124
return $callbackKey . $argumentKey;
121125
}
122126

123-
if (! is_callable($callback, false, $callbackKey)) {
124-
throw new Exception\InvalidArgumentException('Invalid callback');
125-
}
126-
127127
// functions, methods and classnames are case-insensitive
128128
$callbackKey = strtolower($callbackKey);
129129

test/Pattern/TestAsset/TestObjectCache.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace LaminasTest\Cache\Pattern\TestAsset;
66

7+
use Closure;
8+
79
use function func_get_args;
810
use function implode;
911

@@ -22,13 +24,15 @@ final class TestObjectCache
2224
/** @var string */
2325
public $property = 'testProperty';
2426

25-
private \Closure $closure;
27+
private Closure $closure;
2628

2729
public function __construct()
2830
{
2931
// Closures prevent serialization - this acts as a detector to verify this object is not serialized during test.
30-
$this->closure = function () {};
32+
$this->closure = function (): void {
33+
};
3134
}
35+
3236
public function bar(): string
3337
{
3438
++static::$fooCounter;

0 commit comments

Comments
 (0)