Skip to content

Commit

Permalink
Merge pull request #28 from ray-di/php8.4
Browse files Browse the repository at this point in the history
Enable PHP 8.4 compat
  • Loading branch information
koriym authored Jan 10, 2025
2 parents 81d262d + 63bc7bd commit d550309
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 507 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
cs:
uses: ray-di/.github/.github/workflows/coding-standards.yml@v1
with:
php_version: 8.3
php_version: 8.4
3 changes: 0 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
- ubuntu-latest
- windows-latest
php-version:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
sa:
uses: ray-di/.github/.github/workflows/static-analysis.yml@v1
with:
php_version: 8.3
php_version: 8.4
has_crc_config: true
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ray/psr-cache-module",
"description": "",
"description": "PSR-6 PSR-16 cache module for Ray.Di",
"license": "MIT",
"authors": [
{
Expand All @@ -9,10 +9,10 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"php": "^8.1",
"psr/cache": "^1.0.1 || ^2.0 || ^3.0",
"ray/di": "^2.13.2",
"symfony/cache": "^5.3.4 || ^6.0 || ^7.1",
"symfony/cache": "^6.0 || ^7.2",
"doctrine/annotations": "^1.13 || ^2.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0",
"ray/aop": "^2.10.4"
Expand Down
6 changes: 1 addition & 5 deletions src/Annotation/CacheDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#[Qualifier]
final class CacheDir
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
6 changes: 1 addition & 5 deletions src/Annotation/CacheNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#[Qualifier]
final class CacheNamespace
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
6 changes: 1 addition & 5 deletions src/Annotation/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#[Qualifier]
final class Local
{
/** @var string */
public $value;

public function __construct(string $value = 'cache')
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
6 changes: 1 addition & 5 deletions src/Annotation/MemcacheConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#[Qualifier]
final class MemcacheConfig
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
6 changes: 1 addition & 5 deletions src/Annotation/RedisConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#[Qualifier]
final class RedisConfig
{
/** @var string */
public $value;

public function __construct(string $value)
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
6 changes: 5 additions & 1 deletion src/Annotation/RedisInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

/**
* @Annotation
* @Qualifier()
* @Qualifier
* @NamedArgumentConstructor
*/
#[Attribute]
#[Qualifier]
final class RedisInstance
{
public function __construct(public string $value = '')
{
}
}
6 changes: 1 addition & 5 deletions src/Annotation/Shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#[Qualifier]
final class Shared
{
/** @var string */
public $value;

public function __construct(string $value = 'cache')
public function __construct(public string $value = '')
{
$this->value = $value;
}
}
7 changes: 1 addition & 6 deletions src/CacheDirModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@

final class CacheDirModule extends AbstractModule
{
/** @var string */
private $cacheDir;

public function __construct(string $cacheDir, ?AbstractModule $module = null)
public function __construct(private readonly string $cacheDir, ?AbstractModule $module = null)
{
$this->cacheDir = $cacheDir;

parent::__construct($module);
}

Expand Down
7 changes: 1 addition & 6 deletions src/CacheNamespaceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@

final class CacheNamespaceModule extends AbstractModule
{
/** @var string */
private $namespace;

public function __construct(string $namespace, ?AbstractModule $module = null)
public function __construct(private readonly string $namespace, ?AbstractModule $module = null)
{
$this->namespace = $namespace;

parent::__construct($module);
}

Expand Down
16 changes: 8 additions & 8 deletions src/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class FilesystemAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

/**
* @CacheNamespace("namespace")
* @CacheDir("directory")
*/
#[CacheNamespace('namespace')]
#[CacheDir('directory')]
public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, ?MarshallerInterface $marshaller = null)
{
public function __construct(
#[CacheNamespace]
string $namespace = '',
int $defaultLifetime = 0,
#[CacheDir]
?string $directory = null,
?MarshallerInterface $marshaller = null
) {
$this->args = func_get_args();

parent::__construct($namespace, $defaultLifetime, $directory, $marshaller);
Expand Down
6 changes: 1 addition & 5 deletions src/LocalCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ final class LocalCacheProvider implements ProviderInterface
/** @var string */
private $cacheDir;

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

#[CacheDir('cacheDir')]
#[CacheNamespace('namespace')]
public function __construct(string $cacheDir = '', string $namespace = '')
public function __construct(string $cacheDir = '', private readonly string $namespace = '')
{
$this->cacheDir = $cacheDir ?: sys_get_temp_dir();
$this->namespace = $namespace;
}

public function get(): AbstractAdapter
Expand Down
16 changes: 6 additions & 10 deletions src/MemcachedProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@
/** @implements ProviderInterface<Memcached> */
class MemcachedProvider implements ProviderInterface
{
/**
* memcached server list
*
* @var array<array<string>>
*/
private $servers;

/**
* @param array<array<string>> $servers
*
* @MemcacheConfig("servers")
* @see https://www.php.net/manual/en/memcached.addservers.php
*/
#[MemcacheConfig('servers')]
public function __construct(array $servers)
{
$this->servers = $servers;
public function __construct(
/**
* memcached server list
*/
private readonly array $servers
) {
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/PhpFileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class PhpFileAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

/** @CacheNamespace("namespace") */
#[CacheNamespace('namespace')]
public function __construct(string $namespace = '', int $defaultLifetime = 0, ?string $directory = null, bool $appendOnly = false)
{
public function __construct(
#[CacheNamespace]
string $namespace = '',
int $defaultLifetime = 0,
?string $directory = null,
bool $appendOnly = false
) {
$this->args = func_get_args();

parent::__construct($namespace, $defaultLifetime, $directory, $appendOnly);
Expand Down
4 changes: 1 addition & 3 deletions src/Psr6MemcachedModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ final class Psr6MemcachedModule extends AbstractModule

public function __construct(string $servers, ?AbstractModule $module = null)
{
$this->servers = array_map(static function ($serverString) {
return explode(':', $serverString);
}, explode(',', $servers));
$this->servers = array_map(static fn ($serverString) => explode(':', $serverString), explode(',', $servers));

parent::__construct($module);
}
Expand Down
19 changes: 9 additions & 10 deletions src/RedisAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ class RedisAdapter extends OriginAdapter implements Serializable
{
use SerializableTrait;

/**
* @param ProviderInterface<Redis> $redisProvider
*
* @CacheNamespace("namespace")
* @Named("redisProvider=redis")
*/
#[CacheNamespace('namespace')]
#[Named('redisProvider=redis')]
public function __construct(ProviderInterface $redisProvider, string $namespace = '', int $defaultLifetime = 0, ?MarshallerInterface $marshaller = null)
{
/** @param ProviderInterface<Redis> $redisProvider */
public function __construct(
#[Named('redis')]
ProviderInterface $redisProvider,
#[CacheNamespace]
string $namespace = '',
int $defaultLifetime = 0,
?MarshallerInterface $marshaller = null
) {
$this->args = func_get_args();

parent::__construct($redisProvider->get(), $namespace, $defaultLifetime, $marshaller);
Expand Down
6 changes: 1 addition & 5 deletions src/RedisProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
/** @implements ProviderInterface<Redis> */
class RedisProvider implements ProviderInterface
{
/** @var list<string> */
private $server;

/**
* @param list<string> $server
*
* @RedisConfig("server")
*/
#[RedisConfig('server')]
public function __construct(array $server)
public function __construct(private array $server)
{
$this->server = $server;
}

/**
Expand Down
16 changes: 4 additions & 12 deletions tests/MemcachedAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ public function testSerialize(): array
{
$provider = new MemcachedProvider([['127.0.0.1', '11211']]);
$adapter = new MemcachedAdapter($provider);
$adapter->get('foo', static function (ItemInterface $item) {
return 'foobar';
});
$foo = $adapter->get('foo', static function (ItemInterface $item) {
return '_no_serve_';
});
$adapter->get('foo', static fn (ItemInterface $item) => 'foobar');
$foo = $adapter->get('foo', static fn (ItemInterface $item) => '_no_serve_');
$this->assertSame('foobar', $foo);
$string = serialize($adapter);
$this->assertIsString($string);
Expand All @@ -41,15 +37,11 @@ public function testSerialize(): array
public function testUnserialize(array $adapters): void
{
$this->assertInstanceOf(MemcachedAdapter::class, $adapters[1]);
$this->assertSame('foobar', $adapters[1]->get('foo', static function (ItemInterface $item) {
return '_no_serve_in_object';
}));
$this->assertSame('foobar', $adapters[1]->get('foo', static fn (ItemInterface $item) => '_no_serve_in_object'));

$adapter0 = unserialize($adapters[0]);
$this->assertInstanceOf(MemcachedAdapter::class, $adapter0);
$this->assertSame('foobar', $adapter0->get('foo', static function (ItemInterface $item) {
return '_no_serve_in_serialize';
}));
$this->assertSame('foobar', $adapter0->get('foo', static fn (ItemInterface $item) => '_no_serve_in_serialize'));
}

public function testCacheNamespaceModule(): void
Expand Down
16 changes: 4 additions & 12 deletions tests/RedisAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ public function testSerialize(): array
{
$provider = new RedisProvider(['127.0.0.1', '6379']);
$adapter = new RedisAdapter($provider);
$adapter->get('foo', static function (ItemInterface $item) {
return 'foobar';
});
$foo = $adapter->get('foo', static function (ItemInterface $item) {
return '_no_serve_';
});
$adapter->get('foo', static fn (ItemInterface $item) => 'foobar');
$foo = $adapter->get('foo', static fn (ItemInterface $item) => '_no_serve_');
$this->assertSame('foobar', $foo);
$string = serialize($adapter);
$this->assertIsString($string);
Expand All @@ -42,15 +38,11 @@ public function testSerialize(): array
public function testUnserialize(array $adapters): void
{
$this->assertInstanceOf(RedisAdapter::class, $adapters[1]);
$this->assertSame('foobar', $adapters[1]->get('foo', static function (ItemInterface $item) {
return '_no_serve_in_object';
}));
$this->assertSame('foobar', $adapters[1]->get('foo', static fn (ItemInterface $item) => '_no_serve_in_object'));

$adapter0 = unserialize($adapters[0]);
$this->assertInstanceOf(RedisAdapter::class, $adapter0);
$this->assertSame('foobar', $adapter0->get('foo', static function (ItemInterface $item) {
return '_no_serve_in_serialize';
}));
$this->assertSame('foobar', $adapter0->get('foo', static fn (ItemInterface $item) => '_no_serve_in_serialize'));
}

public function testCacheNamespaceModule(): void
Expand Down
5 changes: 5 additions & 0 deletions vendor-bin/metrics/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"phpmetrics/phpmetrics": "^2.8"
}
}
Loading

0 comments on commit d550309

Please sign in to comment.