Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Check coding standards
run: composer cs-check
run: vendor/bin/php-cs-fixer fix --dry-run --diff

stan:
name: PHPStan
Expand All @@ -58,10 +58,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "8.1", "8.2", "8.3", "8.4"]
php: ["8.2", "8.3", "8.4", "8.5"]
deps: ["highest"]
include:
- php: "8.0"
- php: "8.2"
deps: "lowest"
steps:
- uses: actions/checkout@v4
Expand Down
47 changes: 30 additions & 17 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,44 @@

declare(strict_types=1);

/*
* Shared php-cs-fixer configuration for every InitPHP package (ADR-005).
*
* This file is identical in all repositories as `.php-cs-fixer.dist.php`.
* The only package-specific part is the two lines below; scripts/check-cs-config.sh
* ignores exactly those two lines when it compares a package with this template.
* Keep each of them on a single line.
*/
$excludeDirs = [];
$excludePaths = [];

$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->name('*.php');

foreach ($excludeDirs as $excludeDir) {
$finder->exclude($excludeDir);
}

foreach ($excludePaths as $excludePath) {
$finder->notPath($excludePath);
}

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRiskyAllowed(false)
->setRules([
'@PSR12' => true,
'@PSR12:risky' => true,
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'declare_strict_types' => true,
'native_function_invocation' => [
'include' => ['@compiler_optimized'],
'scope' => 'namespaced',
'strict' => true,
],
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'@PER-CS' => true,
'@PHP8x2Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'no_unused_imports' => true,
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
'sort_algorithm' => 'alpha',
],
'single_quote' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'single_quote' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters'],
],
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/build/php-cs-fixer.cache');
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to `initphp/cache` are documented here. The format is based
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- **BREAKING:** Raised the minimum PHP version to 8.2 (`"php": "^8.2"`). The
CI matrix now covers PHP 8.2, 8.3, 8.4 and 8.5.
- **BREAKING:** The code style moved to PER-CS, enforced by the shared
PHP-CS-Fixer configuration (`.php-cs-fixer.dist.php`). The source was
reformatted accordingly; there are no behaviour changes.

## [1.0.0]

The first stable release: a modern PHP 8 codebase, real bug fixes, full
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Redis, Memcache(d) and WinCache.

## Requirements

- PHP 8.0 or higher
- PHP 8.2 or higher
- [`psr/simple-cache`](https://packagist.org/packages/psr/simple-cache) `^3.0`

Each handler may need its own PHP extension:
Expand Down Expand Up @@ -122,7 +122,7 @@ configuration and the exact semantics of TTLs, keys and counters.
## Contributing

Bug reports and pull requests are welcome. CI runs PHP-CS-Fixer, PHPStan (max
level) and PHPUnit across PHP 8.0–8.4, plus a Redis/Memcached integration job.
level) and PHPUnit across PHP 8.2–8.5, plus a Redis/Memcached integration job.
Run the same static bundle locally with:

```bash
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"docs": "https://github.com/InitPHP/Cache/tree/main/docs"
},
"require": {
"php": ">=8.0",
"php": "^8.2",
"psr/simple-cache": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "^1.12 || ^2.1",
"friendsofphp/php-cs-fixer": "^3.65"
"friendsofphp/php-cs-fixer": "^3.95"
},
"suggest": {
"ext-pdo": "To use the PDO handler.",
Expand Down
12 changes: 6 additions & 6 deletions src/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public function __construct(array $options = [])
if (!$this->isSupported()) {
throw new CacheException(\sprintf(
'The "%s" cache handler is not supported in this environment; the required extension is missing or disabled.',
static::class
static::class,
));
}
$this->options = array_merge(
self::DEFAULT_OPTIONS,
array_change_key_case($this->handlerOptions),
array_change_key_case($options)
array_change_key_case($options),
);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ abstract public function get(string $key, mixed $default = null): mixed;
/**
* @inheritDoc
*/
abstract public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool;
abstract public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool;

/**
* @inheritDoc
Expand Down Expand Up @@ -209,7 +209,7 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable
*
* @param iterable<string, mixed> $values
*/
public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
public function setMultiple(iterable $values, int|DateInterval|null $ttl = null): bool
{
$result = true;
foreach ($values as $key => $value) {
Expand Down Expand Up @@ -254,7 +254,7 @@ protected function validateKey(string $key): string
throw new InvalidArgumentException(\sprintf(
'The cache key "%s" contains a reserved character. The following are reserved: %s',
$key,
self::RESERVED_CHARACTERS
self::RESERVED_CHARACTERS,
));
}

Expand Down Expand Up @@ -285,7 +285,7 @@ protected function name(string $key): string
* @param null|int|DateInterval $ttl
* @return int|null
*/
protected function ttlToSeconds(null|int|DateInterval $ttl): ?int
protected function ttlToSeconds(int|DateInterval|null $ttl): ?int
{
if ($ttl === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function create(string|CacheInterface $handler, array $options = [

throw new CacheException(\sprintf(
'The cache handler must implement %s.',
CacheInterface::class
CacheInterface::class,
));
}
}
4 changes: 1 addition & 3 deletions src/Exception/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@
* Implements {@see PsrCacheException} so that, per PSR-16, every exception the
* library throws can be caught through the PSR interface.
*/
class CacheException extends Exception implements PsrCacheException
{
}
class CacheException extends Exception implements PsrCacheException {}
4 changes: 1 addition & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@
* Extends the SPL {@see PhpInvalidArgumentException} and implements the PSR-16
* {@see PsrInvalidArgumentException}, so it can be caught either way.
*/
class InvalidArgumentException extends PhpInvalidArgumentException implements PsrInvalidArgumentException
{
}
class InvalidArgumentException extends PhpInvalidArgumentException implements PsrInvalidArgumentException {}
6 changes: 3 additions & 3 deletions src/Handler/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class File extends BaseHandler
*/
protected array $handlerOptions = [
'path' => null,
'mode' => 0640,
'mode' => 0o640,
];

/**
Expand All @@ -74,7 +74,7 @@ public function get(string $key, mixed $default = null): mixed
/**
* @inheritDoc
*/
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$name = $this->name($key);
$seconds = $this->ttlToSeconds($ttl);
Expand Down Expand Up @@ -147,7 +147,7 @@ private function write(string $path, string $content): bool
if (@file_put_contents($path, $content) === false) {
return false;
}
$mode = $this->getOption('mode', 0640);
$mode = $this->getOption('mode', 0o640);
if (\is_int($mode)) {
@chmod($path, $mode);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/Memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function get(string $key, mixed $default = null): mixed
/**
* @inheritDoc
*/
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$name = $this->name($key);
$seconds = $this->ttlToSeconds($ttl);
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function get(string $key, mixed $default = null): mixed
/**
* @inheritDoc
*/
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$name = $this->name($key);
$seconds = $this->ttlToSeconds($ttl);
Expand Down Expand Up @@ -176,7 +176,7 @@ protected function getPDO(): PdoConnection
[
PdoConnection::ATTR_ERRMODE => PdoConnection::ERRMODE_EXCEPTION,
PdoConnection::ATTR_DEFAULT_FETCH_MODE => PdoConnection::FETCH_ASSOC,
]
],
);
} catch (PDOException $e) {
throw new CacheException('PDO cache connection error: ' . $e->getMessage(), 0, $e);
Expand Down
4 changes: 2 additions & 2 deletions src/Handler/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function get(string $key, mixed $default = null): mixed
/**
* @inheritDoc
*/
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$name = $this->name($key);
$seconds = $this->ttlToSeconds($ttl);
Expand Down Expand Up @@ -150,7 +150,7 @@ protected function getRedis(): RedisExtension
$connected = $redis->connect(
$this->optionString('host', '127.0.0.1'),
$this->optionInt('port', 6379),
$this->optionFloat('timeout', 0.0)
$this->optionFloat('timeout', 0.0),
);
if (!$connected) {
throw new CacheException('Redis cache connection failed.');
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/Wincache.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function get(string $key, mixed $default = null): mixed
/**
* @inheritDoc
*/
public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$name = $this->name($key);
$seconds = $this->ttlToSeconds($ttl);
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/ArrayHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function get(string $key, mixed $default = null): mixed
return $this->store[$name]['value'];
}

public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
$name = $this->name($key);
$seconds = $this->ttlToSeconds($ttl);
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/ProbeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function get(string $key, mixed $default = null): mixed
return $default;
}

public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
return true;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ public function exposeName(string $key): string
return $this->name($key);
}

public function exposeTtlToSeconds(null|int|DateInterval $ttl): ?int
public function exposeTtlToSeconds(int|DateInterval|null $ttl): ?int
{
return $this->ttlToSeconds($ttl);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/RejectingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function get(string $key, mixed $default = null): mixed
return $default;
}

public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/UnsupportedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function get(string $key, mixed $default = null): mixed
return $default;
}

public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
public function set(string $key, mixed $value, int|DateInterval|null $ttl = null): bool
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Handler/FileHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class FileHandlerTest extends AbstractCacheContractTestCase
protected function setUp(): void
{
$this->dir = sys_get_temp_dir() . '/initphp-cache-' . uniqid('', true);
mkdir($this->dir, 0777, true);
mkdir($this->dir, 0o777, true);
parent::setUp();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Handler/PdoHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function setUp(): void
$this->raw = new PDO('sqlite:' . $this->dbFile);
$this->raw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->raw->exec(
'CREATE TABLE cache (name VARCHAR(255) NOT NULL, ttl INTEGER NULL DEFAULT NULL, data TEXT NOT NULL, UNIQUE(name))'
'CREATE TABLE cache (name VARCHAR(255) NOT NULL, ttl INTEGER NULL DEFAULT NULL, data TEXT NOT NULL, UNIQUE(name))',
);
parent::setUp();
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testConnectionErrorThrowsCacheException(): void
public function testExpiredRowIsTreatedAsMissAndDeleted(): void
{
$this->raw->exec(
"INSERT INTO cache (name, ttl, data) VALUES ('cache_old', " . (time() - 60) . ", '" . serialize('v') . "')"
"INSERT INTO cache (name, ttl, data) VALUES ('cache_old', " . (time() - 60) . ", '" . serialize('v') . "')",
);

self::assertNull($this->cache->get('old'));
Expand Down
Loading