Skip to content

Commit

Permalink
Update to php 8 (#27)
Browse files Browse the repository at this point in the history
* Update to php 8.1

* Use php 8 with BC check

* Fix for cache 3.0

* Report coverage on 8.0
  • Loading branch information
RikudouSage committed Feb 9, 2023
1 parent 0130d63 commit 868ecc0
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 296 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bc_check.yaml
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Checkout Code
uses: actions/checkout@v2
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Expand Up @@ -13,7 +13,7 @@ jobs:
PHP_CS_FIXER_IGNORE_ENV: yes
strategy:
matrix:
version: ['7.3', '7.4', '8.0', '8.1']
version: ['8.0', '8.1', '8.2']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['7.3', '7.4', '8.0', '8.1']
version: ['8.0', '8.1', '8.2']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['7.3', '7.4', '8.0', '8.1']
version: ['8.0', '8.1', '8.2']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -66,7 +66,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
- name: Checkout Code
uses: actions/checkout@v2
- name: Install Dependencies
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -4,7 +4,7 @@
"minimum-stability": "stable",
"license": "MIT",
"require": {
"psr/cache": "^1.0 | ^2.0 | ^3.0",
"psr/cache": "^2.0 | ^3.0",
"php": "^8.0",
"rikudou/clock": "^1.0",
"psr/simple-cache": "^1.0",
Expand All @@ -22,7 +22,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.43",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.3",
"ext-json": "*",
"jetbrains/phpstorm-attributes": "^1.0"
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon.dist
@@ -1,2 +1,4 @@
parameters:
treatPhpDocTypesAsCertain: false
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#expects int<.+?>, int given#'
2 changes: 1 addition & 1 deletion src/Converter/CacheItemConverterRegistry.php
Expand Up @@ -11,7 +11,7 @@ final class CacheItemConverterRegistry
/**
* @var CacheItemConverterInterface[]
*/
private $converters;
private array $converters;

public function __construct(CacheItemConverterInterface ...$converters)
{
Expand Down
12 changes: 3 additions & 9 deletions src/Converter/DefaultCacheItemConverter.php
Expand Up @@ -11,15 +11,9 @@

final class DefaultCacheItemConverter implements CacheItemConverterInterface
{
/**
* @var CacheItemEncoderInterface
*/
private $encoder;

/**
* @var ClockInterface
*/
private $clock;
private CacheItemEncoderInterface $encoder;

private ClockInterface $clock;

public function __construct(?CacheItemEncoderInterface $encoder = null, ClockInterface $clock = null)
{
Expand Down
81 changes: 11 additions & 70 deletions src/DynamoCacheItem.php
Expand Up @@ -7,64 +7,22 @@
use Psr\Cache\CacheItemInterface;
use Rikudou\Clock\ClockInterface;
use Rikudou\DynamoDbCache\Encoder\CacheItemEncoderInterface;
use Rikudou\DynamoDbCache\Exception\InvalidArgumentException;

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

/**
* @var bool
*/
private $isHit;

/**
* @var DateTimeInterface|null
*/
private $expiresAt;

/**
* @var string
*/
private $value;

/**
* @var ClockInterface
*/
private $clock;

/**
* @var CacheItemEncoderInterface
*/
private $encoder;

/**
* @param string $key
* @param bool $isHit
* @param mixed $value
* @param DateTimeInterface|null $expiresAt
* @param ClockInterface $clock
* @param CacheItemEncoderInterface $encoder
*
* @internal
*/
public function __construct(
string $key,
bool $isHit,
$value,
?DateTimeInterface $expiresAt,
ClockInterface $clock,
CacheItemEncoderInterface $encoder
private string $key,
private bool $isHit,
mixed $value,
private ?DateTimeInterface $expiresAt,
private ClockInterface $clock,
private CacheItemEncoderInterface $encoder
) {
$this->key = $key;
$this->isHit = $isHit;
$this->expiresAt = $expiresAt;
$this->clock = $clock;
$this->encoder = $encoder;

$this->set($value);
}

Expand All @@ -83,33 +41,25 @@ public function isHit(): bool
return $this->isHit && ($this->clock->now() < $this->expiresAt || $this->expiresAt === null);
}

public function set($value): static
public function set(mixed $value): static
{
$this->value = $this->encoder->encode($value);

return $this;
}

/**
* @param ?\DateTimeInterface $expiration
*/
public function expiresAt($expiration): static
public function expiresAt(?DateTimeInterface $expiration): static
{
if ($expiration === null) {
$this->expiresAt = null;
} elseif ($expiration instanceof DateTimeInterface) {
$this->expiresAt = $expiration;
} else {
throw new InvalidArgumentException('The expiration must be null or instance of ' . DateTimeInterface::class);
$this->expiresAt = $expiration;
}

return $this;
}

/**
* @param int|\DateInterval|null $time
*/
public function expiresAfter($time): static
public function expiresAfter(DateInterval|int|null $time): static
{
if ($time === null) {
$this->expiresAt = null;
Expand All @@ -118,9 +68,6 @@ public function expiresAfter($time): static
if (is_int($time)) {
$time = new DateInterval("PT{$time}S");
}
if (!$time instanceof DateInterval) {
throw new InvalidArgumentException('The argument must be an int, DateInterval or null');
}

assert(method_exists($now, 'add'));
$this->expiresAt = $now->add($time);
Expand All @@ -130,21 +77,15 @@ public function expiresAfter($time): static
}

/**
* @return string
*
* @internal
*
*/
public function getRaw(): string
{
return $this->value;
}

/**
* @return DateTimeInterface|null
*
* @internal
*
*/
public function getExpiresAt(): ?DateTimeInterface
{
Expand Down

0 comments on commit 868ecc0

Please sign in to comment.