Skip to content

Commit

Permalink
Changes for release compatible with psr/cache 3.0
Browse files Browse the repository at this point in the history
- add type hints for arguments and return type hints
- update dependencies
  - psr/cache ^3.0
  - php (^8.0.0, same requirements as psr/cache ^3.0)
  • Loading branch information
David Weichert committed Mar 12, 2024
1 parent afd879f commit e35ef3f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 76 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"license": "MIT",
"minimum-stability": "stable",
"require": {
"psr/cache": "^1.0"
"psr/cache": "^3.0",
"php": ">=8.0.0"
},
"require-dev": {
"phpunit/phpunit": "^11"
Expand Down
3 changes: 0 additions & 3 deletions src/CacheItemPoolAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface CacheItemPoolAwareInterface
{
/**
* @param CacheItemPoolInterface $cacheItemPool
*/
public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool);
}
7 changes: 2 additions & 5 deletions src/CacheItemPoolAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

trait CacheItemPoolAwareTrait
{
/**
* @var CacheItemPoolInterface
*/
protected $cacheItemPool;
protected CacheItemPoolInterface $cacheItemPool;

public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool)
public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool): void
{
$this->cacheItemPool = $cacheItemPool;
}
Expand Down
40 changes: 9 additions & 31 deletions src/NullCacheItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,45 @@

namespace Metasyntactical\Psr\Cache;

use DateInterval;
use DateTimeInterface;
use Psr\Cache\CacheItemInterface;

final class NullCacheItem implements CacheItemInterface
{
/**
* @var string
*/
private $key;
private string $key;

/**
* @param string $key
*/
public function __construct($key)
{
$this->key = (string) $key;
}

/**
* @inheritDoc
*/
public function getKey()
public function getKey(): string
{
return $this->key;
}

/**
* @inheritDoc
*/
public function get()
public function get(): mixed
{
return null;
}

/**
* @inheritDoc
*/
public function isHit()
public function isHit(): bool
{
return false;
}

/**
* @inheritDoc
*/
public function set($value)
public function set(mixed $value): static
{
return $this;
}

/**
* @inheritDoc
*/
public function expiresAt($expiration)
public function expiresAt(?DateTimeInterface $expiration): static
{
return $this;
}

/**
* @inheritDoc
*/
public function expiresAfter($time)
public function expiresAfter(int|DateInterval|null $time): static
{
return $this;
}
Expand Down
46 changes: 10 additions & 36 deletions src/NullCacheItemPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@

final class NullCacheItemPool implements CacheItemPoolInterface
{
/**
* {@inheritdoc}
*/
public function getItem($key)

public function getItem(string $key): CacheItemInterface
{
return new NullCacheItem($key);
}

/**
* {@inheritdoc}
*/
public function getItems(array $keys = array())
public function getItems(array $keys = []): iterable
{
return array_combine(
$keys,
Expand All @@ -31,58 +26,37 @@ function ($key) {
);
}

/**
* {@inheritdoc}
*/
public function hasItem($key)
public function hasItem(string $key): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function clear()
public function clear(): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function deleteItem($key)
public function deleteItem(string $key): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function deleteItems(array $keys)
public function deleteItems(array $keys): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function save(CacheItemInterface $item)
public function save(CacheItemInterface $item): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function saveDeferred(CacheItemInterface $item)
public function saveDeferred(CacheItemInterface $item): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function commit()
public function commit(): bool
{
return true;
}
Expand Down

0 comments on commit e35ef3f

Please sign in to comment.