Skip to content

Commit

Permalink
Make codestyle happy
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Rautenberg <[email protected]>
  • Loading branch information
SvenRtbg committed Jan 14, 2025
1 parent 523e13c commit eb54767
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@
<PossiblyUnusedProperty>
<code><![CDATA[$property]]></code>
</PossiblyUnusedProperty>
<UnusedProperty>
<code><![CDATA[$closure]]></code>
</UnusedProperty>
</file>
<file src="test/Psr/CacheItemPool/CacheItemPoolDecoratorTest.php">
<InvalidArgument>
Expand Down
10 changes: 5 additions & 5 deletions src/Pattern/CallbackCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use function array_key_exists;
use function array_values;
use function is_array;
use function is_callable;
use function is_object;
use function md5;
Expand Down Expand Up @@ -111,19 +112,18 @@ public function generateKey(callable $callback, array $args = []): string
*/
protected function generateCallbackKey(callable $callback, array $args): string
{
if (! is_callable($callback, false, $callbackKey)) {
throw new Exception\InvalidArgumentException('Invalid callback');
}

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

if (! is_callable($callback, false, $callbackKey)) {
throw new Exception\InvalidArgumentException('Invalid callback');
}

// functions, methods and classnames are case-insensitive
$callbackKey = strtolower($callbackKey);

Expand Down
8 changes: 6 additions & 2 deletions test/Pattern/TestAsset/TestObjectCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace LaminasTest\Cache\Pattern\TestAsset;

use Closure;

use function func_get_args;
use function implode;

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

private \Closure $closure;
private Closure $closure;

public function __construct()
{
// Closures prevent serialization - this acts as a detector to verify this object is not serialized during test.
$this->closure = function () {};
$this->closure = function (): void {
};
}

public function bar(): string
{
++static::$fooCounter;
Expand Down

0 comments on commit eb54767

Please sign in to comment.