Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce support for PSR-6 and PSR-16 v2 & v3 #275

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{
"backwardCompatibilityCheck": true
"backwardCompatibilityCheck": true,
"additional_checks": [
{
"name": "Unit tests with psr/cache v2",
"job": {
"php": "*",
"dependencies": "locked",
"command": "composer require psr/cache:^2.0 && vendor/bin/phpunit"
}
},

{
"name": "Unit tests with psr/simple-cache v2",
"job": {
"php": "*",
"dependencies": "locked",
"command": "composer require psr/simple-cache:^2.0 && vendor/bin/phpunit"
}
}
]
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"laminas/laminas-eventmanager": "^3.4",
"laminas/laminas-servicemanager": "^3.21",
"laminas/laminas-stdlib": "^3.6",
"psr/cache": "^1.0",
"psr/simple-cache": "^1.0",
"psr/cache": "^2.0 || ^3.0",
"psr/simple-cache": "^2.0 || ^3.0",
"psr/clock": "^1.0",
"webmozart/assert": "^1.9"
},
Expand Down
36 changes: 18 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,12 @@
<DocblockTypeContradiction>
<code>is_array($result)</code>
</DocblockTypeContradiction>
<MissingReturnType>
<code>validateKey</code>
<code>validateKeys</code>
<code>validateStorage</code>
</MissingReturnType>
<UndefinedInterfaceMethod>
<code>flush</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Psr/SimpleCache/SimpleCacheDecorator.php">
<DocblockTypeContradiction>
<code>null === $ttl</code>
</DocblockTypeContradiction>
<MixedArgument>
<code>$key</code>
<code>$key</code>
</MixedArgument>
<PossiblyNullArgument>
<code>$ttl</code>
<code>$ttl</code>
</PossiblyNullArgument>
<RedundantConditionGivenDocblockType>
<code><![CDATA[null !== $this->storage->removeItem($key)]]></code>
</RedundantConditionGivenDocblockType>
Expand Down Expand Up @@ -771,7 +756,6 @@
<file src="test/Psr/CacheItemPool/CacheItemTest.php">
<InvalidArgument>
<code><![CDATA['foo']]></code>
<code>[]</code>
</InvalidArgument>
</file>
<file src="test/Psr/SimpleCache/SimpleCacheDecoratorTest.php">
Expand All @@ -784,24 +768,17 @@
</DeprecatedMethod>
<MissingReturnType>
<code>testHasProxiesToStorage</code>
<code>testSetMultipleRaisesExceptionWhenTtlValueIsInvalid</code>
<code>testSetMultipleShouldRaisePsrInvalidArgumentExceptionForInvalidKeys</code>
<code>testSetMultipleShouldRemoveItemsFromCacheIfTtlIsBelow1</code>
<code>testSetMultipleShouldRemoveItemsFromCacheIfTtlIsBelow1AndStorageDoesNotSupportPerItemTtl</code>
<code>testSetRaisesExceptionWhenTtlValueIsInvalid</code>
<code>testSetShouldAcknowledgeStorageAdapterMaxKeyLengthWithPsrDecorator</code>
<code>testSetShouldRaisePsrInvalidArgumentExceptionForInvalidKeys</code>
<code>testSetShouldRemoveItemFromCacheIfTtlIsBelow1</code>
<code>testSetShouldRemoveItemFromCacheIfTtlIsBelow1AndStorageDoesNotSupportPerItemTtl</code>
</MissingReturnType>
<MixedArgument>
<code>$ttl</code>
<code>$ttl</code>
</MixedArgument>
<MixedInferredReturnType>
<code>array</code>
<code>array</code>
<code>array</code>
</MixedInferredReturnType>
</file>
<file src="test/Psr/SimpleCache/TestAsset/TtlStorage.php">
Expand Down
28 changes: 7 additions & 21 deletions src/Psr/CacheItemPool/CacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Psr\Cache\CacheItemInterface;
use Psr\Clock\ClockInterface;

use function gettype;
use function is_int;
use function sprintf;

Expand All @@ -20,13 +19,6 @@
*/
final class CacheItem implements CacheItemInterface
{
/**
* Cache value
*
* @var mixed|null
*/
private $value;

/**
* Timestamp item will expire at if expiresAt() called, null otherwise
*/
Expand All @@ -36,15 +28,14 @@ final class CacheItem implements CacheItemInterface

public function __construct(
private string $key,
mixed $value,
private mixed $value,
/**
* True if the cache item lookup resulted in a cache hit or if they item is deferred or successfully saved
*/
private bool $isHit,
?ClockInterface $clock = null
) {
$this->value = $isHit ? $value : null;
$this->isHit = $isHit;
$clock ??= new class implements ClockInterface
{
public function now(): DateTimeImmutable
Expand All @@ -66,7 +57,7 @@ public function getKey(): string
/**
* {@inheritdoc}
*/
public function get()
public function get(): mixed
{
return $this->value;
}
Expand Down Expand Up @@ -99,7 +90,7 @@ public function setIsHit(bool $isHit): self
/**
* {@inheritdoc}
*/
public function set($value): CacheItemInterface
public function set($value): static
{
$this->value = $value;

Expand All @@ -109,7 +100,7 @@ public function set($value): CacheItemInterface
/**
* {@inheritdoc}
*/
public function expiresAt($expiration): CacheItemInterface
public function expiresAt($expiration): static
{
if (! ($expiration === null || $expiration instanceof DateTimeInterface)) {
throw new InvalidArgumentException('$expiration must be null or an instance of DateTimeInterface');
Expand All @@ -123,7 +114,7 @@ public function expiresAt($expiration): CacheItemInterface
/**
* {@inheritdoc}
*/
public function expiresAfter($time): CacheItemInterface
public function expiresAfter($time): static
{
if ($time === null) {
return $this->expiresAt(null);
Expand All @@ -138,13 +129,8 @@ public function expiresAfter($time): CacheItemInterface
$time = $interval;
}

/** @psalm-suppress RedundantConditionGivenDocblockType Until we do have native type-hints we should keep verifying this. */
if ($time instanceof DateInterval) {
$now = $this->clock->now();
return $this->expiresAt($now->add($time));
}

throw new InvalidArgumentException(sprintf('Invalid $time "%s"', gettype($time)));
$now = $this->clock->now();
return $this->expiresAt($now->add($time));
}

/**
Expand Down
Loading