diff --git a/rector.php b/rector.php index 65fe6cd0..16ea5779 100644 --- a/rector.php +++ b/rector.php @@ -2,23 +2,20 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; -use Rector\Ray\AnnotationBinding\Rector\ClassMethod\AnnotationBindingRector; -use Rector\Set\ValueObject\LevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ + __DIR__ . '/demo', __DIR__ . '/src', __DIR__ . '/src-annotation', - __DIR__ . '/tests/*/*Test.php', - ]); - - // register a single rule - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); - $rectorConfig->rule(AnnotationBindingRector::class); - // define sets of rules - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, - ]); -}; + __DIR__ . '/src-annotation-deprecated', + __DIR__ . '/tests', + __DIR__ . '/tests-pecl-ext', + __DIR__ . '/tests-php8', + ]) + // uncomment to reach your current PHP version + ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/src-annotation-deprecated/CacheVersion.php b/src-annotation-deprecated/CacheVersion.php index 0abf788c..fbcddf22 100644 --- a/src-annotation-deprecated/CacheVersion.php +++ b/src-annotation-deprecated/CacheVersion.php @@ -15,13 +15,7 @@ #[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier] final class CacheVersion { - /** - * @var string - */ - public $value; - - public function __construct(string $value) + public function __construct(public string $value) { - $this->value = $value; } } diff --git a/src-annotation/Commands.php b/src-annotation/Commands.php index 1d8ed536..7c8e8fd7 100644 --- a/src-annotation/Commands.php +++ b/src-annotation/Commands.php @@ -7,8 +7,6 @@ use Attribute; use Ray\Di\Di\Qualifier; -/** - */ #[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)] #[Qualifier] final class Commands diff --git a/src-annotation/RefreshCache.php b/src-annotation/RefreshCache.php index cee83590..7788f781 100644 --- a/src-annotation/RefreshCache.php +++ b/src-annotation/RefreshCache.php @@ -7,9 +7,7 @@ use Attribute; use BEAR\QueryRepository\DonutCommandInterceptor; -/** - * @see DonutCommandInterceptor - */ +/** @see DonutCommandInterceptor */ #[Attribute(Attribute::TARGET_METHOD)] final class RefreshCache { diff --git a/src/CacheDependency.php b/src/CacheDependency.php index 1d912e4b..e1fb9a1b 100644 --- a/src/CacheDependency.php +++ b/src/CacheDependency.php @@ -10,10 +10,10 @@ use function assert; use function sprintf; -final class CacheDependency implements CacheDependencyInterface +final readonly class CacheDependency implements CacheDependencyInterface { public function __construct( - private readonly UriTagInterface $uriTag, + private UriTagInterface $uriTag, ) { } diff --git a/src/CacheInterceptor.php b/src/CacheInterceptor.php index daa83169..d37d47c1 100644 --- a/src/CacheInterceptor.php +++ b/src/CacheInterceptor.php @@ -17,10 +17,10 @@ use const E_USER_WARNING; -final class CacheInterceptor implements MethodInterceptor +final readonly class CacheInterceptor implements MethodInterceptor { public function __construct( - private readonly QueryRepositoryInterface $repository, + private QueryRepositoryInterface $repository, ) { } diff --git a/src/Cdn/FastlyCachePurger.php b/src/Cdn/FastlyCachePurger.php index 6127b00c..78473328 100644 --- a/src/Cdn/FastlyCachePurger.php +++ b/src/Cdn/FastlyCachePurger.php @@ -8,9 +8,9 @@ use BEAR\QueryRepository\PurgerInterface; use Override; -final class FastlyCachePurger implements PurgerInterface +final readonly class FastlyCachePurger implements PurgerInterface { - public function __construct(private readonly FastlyCachePurgerInterface $fastlyCachePurger) + public function __construct(private FastlyCachePurgerInterface $fastlyCachePurger) { } diff --git a/src/CliHttpCache.php b/src/CliHttpCache.php index 514681f7..f12b208f 100644 --- a/src/CliHttpCache.php +++ b/src/CliHttpCache.php @@ -16,10 +16,10 @@ use const PHP_EOL; -final class CliHttpCache implements HttpCacheInterface +final readonly class CliHttpCache implements HttpCacheInterface { public function __construct( - private readonly ResourceStorageInterface $storage, + private ResourceStorageInterface $storage, ) { } diff --git a/src/CommandInterceptor.php b/src/CommandInterceptor.php index fbb385f8..3d0d1bf4 100644 --- a/src/CommandInterceptor.php +++ b/src/CommandInterceptor.php @@ -12,12 +12,12 @@ use Ray\Aop\MethodInterceptor; use Ray\Aop\MethodInvocation; -final class CommandInterceptor implements MethodInterceptor +final readonly class CommandInterceptor implements MethodInterceptor { /** @param CommandInterface[] $commands */ public function __construct( #[Commands] - private readonly array $commands, + private array $commands, ) { } diff --git a/src/CommandsProvider.php b/src/CommandsProvider.php index ed20fae7..33687bf1 100644 --- a/src/CommandsProvider.php +++ b/src/CommandsProvider.php @@ -8,11 +8,11 @@ use Ray\Di\ProviderInterface; /** @implements ProviderInterface> */ -final class CommandsProvider implements ProviderInterface +final readonly class CommandsProvider implements ProviderInterface { public function __construct( - private readonly RefreshSameCommand $refreshSameCommand, - private readonly RefreshAnnotatedCommand $refreshAnnotatedCommand, + private RefreshSameCommand $refreshSameCommand, + private RefreshAnnotatedCommand $refreshAnnotatedCommand, ) { } diff --git a/src/DevEtagSetter.php b/src/DevEtagSetter.php index 4fc442b8..752cfe85 100644 --- a/src/DevEtagSetter.php +++ b/src/DevEtagSetter.php @@ -12,10 +12,10 @@ use function gmdate; -final class DevEtagSetter implements EtagSetterInterface +final readonly class DevEtagSetter implements EtagSetterInterface { public function __construct( - private readonly CacheDependencyInterface $cacheDeperency, + private CacheDependencyInterface $cacheDeperency, ) { } diff --git a/src/DonutCommandInterceptor.php b/src/DonutCommandInterceptor.php index 97f499d4..03ed98ea 100644 --- a/src/DonutCommandInterceptor.php +++ b/src/DonutCommandInterceptor.php @@ -19,11 +19,11 @@ use function is_callable; use function sprintf; -final class DonutCommandInterceptor implements MethodInterceptor +final readonly class DonutCommandInterceptor implements MethodInterceptor { public function __construct( - private readonly DonutRepositoryInterface $repository, - private readonly MatchQueryInterface $matchQuery + private DonutRepositoryInterface $repository, + private MatchQueryInterface $matchQuery ){ } diff --git a/src/DonutRepository.php b/src/DonutRepository.php index 4697256e..42997248 100644 --- a/src/DonutRepository.php +++ b/src/DonutRepository.php @@ -12,16 +12,16 @@ use function assert; use function explode; -final class DonutRepository implements DonutRepositoryInterface +final readonly class DonutRepository implements DonutRepositoryInterface { public function __construct( - private readonly QueryRepositoryInterface $queryRepository, - private readonly HeaderSetter $headerSetter, - private readonly ResourceStorageInterface $resourceStorage, - private readonly ResourceInterface $resource, - private readonly CdnCacheControlHeaderSetterInterface $cdnCacheControlHeaderSetter, - private readonly RepositoryLoggerInterface $logger, - private readonly DonutRendererInterface $renderer, + private QueryRepositoryInterface $queryRepository, + private HeaderSetter $headerSetter, + private ResourceStorageInterface $resourceStorage, + private ResourceInterface $resource, + private CdnCacheControlHeaderSetterInterface $cdnCacheControlHeaderSetter, + private RepositoryLoggerInterface $logger, + private DonutRendererInterface $renderer, ) { } diff --git a/src/DonutRequest.php b/src/DonutRequest.php index d025b9e0..b8074b74 100644 --- a/src/DonutRequest.php +++ b/src/DonutRequest.php @@ -10,12 +10,12 @@ use function sprintf; -final class DonutRequest implements Stringable +final readonly class DonutRequest implements Stringable { public function __construct( - private readonly AbstractRequest $request, - private readonly DonutRendererInterface $donutStorage, - private readonly SurrogateKeys $etags, + private AbstractRequest $request, + private DonutRendererInterface $donutStorage, + private SurrogateKeys $etags, ) { } diff --git a/src/EtagSetter.php b/src/EtagSetter.php index 86293289..ece48085 100644 --- a/src/EtagSetter.php +++ b/src/EtagSetter.php @@ -18,10 +18,10 @@ use function serialize; use function time; -final class EtagSetter implements EtagSetterInterface +final readonly class EtagSetter implements EtagSetterInterface { public function __construct( - private readonly CacheDependencyInterface $cacheDeperency, + private CacheDependencyInterface $cacheDeperency, ) { } diff --git a/src/Expiry.php b/src/Expiry.php index 8386f48c..0f70b2d1 100644 --- a/src/Expiry.php +++ b/src/Expiry.php @@ -4,10 +4,10 @@ namespace BEAR\QueryRepository; -final class Expiry +final readonly class Expiry { /** @var array */ - private readonly array $time; + private array $time; public function __construct(int $short = 60, int $medium = 3600, int $long = 86400, int $never = 31_536_000) { diff --git a/src/HeaderSetter.php b/src/HeaderSetter.php index 1826d616..185a040f 100644 --- a/src/HeaderSetter.php +++ b/src/HeaderSetter.php @@ -11,10 +11,10 @@ use function sprintf; use function str_contains; -final class HeaderSetter +final readonly class HeaderSetter { public function __construct( - private readonly EtagSetterInterface $etagSetter, + private EtagSetterInterface $etagSetter, ) { } diff --git a/src/HttpCache.php b/src/HttpCache.php index 290905d0..ef8496f1 100644 --- a/src/HttpCache.php +++ b/src/HttpCache.php @@ -11,10 +11,10 @@ use function http_response_code; /** @psalm-suppress DeprecatedInterface for BC */ -final class HttpCache implements HttpCacheInterface, DeprecatedHttpCacheInterface +final readonly class HttpCache implements HttpCacheInterface, DeprecatedHttpCacheInterface { public function __construct( - private readonly ResourceStorageInterface $storage, + private ResourceStorageInterface $storage, ) { } diff --git a/src/MarshallerProvider.php b/src/MarshallerProvider.php index 28659051..4096546c 100644 --- a/src/MarshallerProvider.php +++ b/src/MarshallerProvider.php @@ -20,12 +20,12 @@ * * @implements ProviderInterface */ -final class MarshallerProvider implements ProviderInterface +final readonly class MarshallerProvider implements ProviderInterface { /** @param array{enabled?: bool, type?: string, use_igbinary?: bool} $options Marshalling options */ public function __construct( #[MarshallerOptions] - private readonly array $options = [], + private array $options = [], ) { } diff --git a/src/QueryRepository.php b/src/QueryRepository.php index f6e0e15e..3a90ff79 100644 --- a/src/QueryRepository.php +++ b/src/QueryRepository.php @@ -17,13 +17,13 @@ use function strtotime; use function time; -final class QueryRepository implements QueryRepositoryInterface +final readonly class QueryRepository implements QueryRepositoryInterface { public function __construct( - private readonly RepositoryLoggerInterface $logger, - private readonly HeaderSetter $headerSetter, - private readonly ResourceStorageInterface $storage, - private readonly Expiry $expiry, + private RepositoryLoggerInterface $logger, + private HeaderSetter $headerSetter, + private ResourceStorageInterface $storage, + private Expiry $expiry, ) { } diff --git a/src/RedisDsnProvider.php b/src/RedisDsnProvider.php index fa097360..50a90be2 100644 --- a/src/RedisDsnProvider.php +++ b/src/RedisDsnProvider.php @@ -17,7 +17,7 @@ use Symfony\Component\Cache\Adapter\RedisAdapter; /** @implements ProviderInterface */ -final class RedisDsnProvider implements ProviderInterface +final readonly class RedisDsnProvider implements ProviderInterface { /** * @param string $dns Redis DSN diff --git a/src/RefreshAnnotatedCommand.php b/src/RefreshAnnotatedCommand.php index 80ce9272..68e6b037 100644 --- a/src/RefreshAnnotatedCommand.php +++ b/src/RefreshAnnotatedCommand.php @@ -16,11 +16,11 @@ use function is_array; use function uri_template; -final class RefreshAnnotatedCommand implements CommandInterface +final readonly class RefreshAnnotatedCommand implements CommandInterface { public function __construct( - private readonly QueryRepositoryInterface $repository, - private readonly ResourceInterface $resource, + private QueryRepositoryInterface $repository, + private ResourceInterface $resource, ) { } diff --git a/src/RefreshInterceptor.php b/src/RefreshInterceptor.php index 4cf94e0a..5d29ca26 100644 --- a/src/RefreshInterceptor.php +++ b/src/RefreshInterceptor.php @@ -11,10 +11,10 @@ use Ray\Aop\MethodInterceptor; use Ray\Aop\MethodInvocation; -final class RefreshInterceptor implements MethodInterceptor +final readonly class RefreshInterceptor implements MethodInterceptor { public function __construct( - private readonly RefreshAnnotatedCommand $command, + private RefreshAnnotatedCommand $command, ) { } diff --git a/src/RefreshSameCommand.php b/src/RefreshSameCommand.php index 4b3df700..0715b531 100644 --- a/src/RefreshSameCommand.php +++ b/src/RefreshSameCommand.php @@ -11,11 +11,11 @@ // phpcs:ignoreFile SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing -- for call_user_func_array -final class RefreshSameCommand implements CommandInterface +final readonly class RefreshSameCommand implements CommandInterface { public function __construct( - private readonly QueryRepositoryInterface $repository, - private readonly MatchQueryInterface $matchQuery + private QueryRepositoryInterface $repository, + private MatchQueryInterface $matchQuery ){ } diff --git a/tests-pecl-ext/StorageRedisDsnModuleTest.php b/tests-pecl-ext/StorageRedisDsnModuleTest.php index b127cce3..7e7b9cd2 100644 --- a/tests-pecl-ext/StorageRedisDsnModuleTest.php +++ b/tests-pecl-ext/StorageRedisDsnModuleTest.php @@ -55,7 +55,7 @@ public static function tearDownAfterClass(): void protected function setUp(): void { - $this->dsn = getenv('REDIS_SERVER') ? getenv('REDIS_SERVER') : 'localhost:6379'; + $this->dsn = getenv('REDIS_SERVER') ?: 'localhost:6379'; } public function testNew(): void diff --git a/tests/Fake/FakeMobileEtagSetter.php b/tests/Fake/FakeMobileEtagSetter.php index 2f4547b0..bfc1de8e 100644 --- a/tests/Fake/FakeMobileEtagSetter.php +++ b/tests/Fake/FakeMobileEtagSetter.php @@ -15,7 +15,7 @@ class FakeMobileEtagSetter implements EtagSetterInterface public static $device; public function __construct( - private MobileEtagSetter $mobileEtagSetter + private readonly MobileEtagSetter $mobileEtagSetter ){ } diff --git a/tests/Fake/fake-app/src/Resource/Page/Html/BlogPostingCacheControl.php b/tests/Fake/fake-app/src/Resource/Page/Html/BlogPostingCacheControl.php index a43dae33..b64dfad9 100644 --- a/tests/Fake/fake-app/src/Resource/Page/Html/BlogPostingCacheControl.php +++ b/tests/Fake/fake-app/src/Resource/Page/Html/BlogPostingCacheControl.php @@ -17,7 +17,7 @@ class BlogPostingCacheControl extends ResourceObject ]; public function __construct( - private DonutRepositoryInterface $repository + private readonly DonutRepositoryInterface $repository ){ } diff --git a/tests/ResourceRepositoryTest.php b/tests/ResourceRepositoryTest.php index 673376b8..abc0a607 100644 --- a/tests/ResourceRepositoryTest.php +++ b/tests/ResourceRepositoryTest.php @@ -27,7 +27,7 @@ protected function setUp(): void { $tagAwareAdapter = new TagAwareAdapter(new FilesystemAdapter('', 0, __DIR__ . '/tmp')); $tagAwareAdapterProvider = new class ($tagAwareAdapter) implements ProviderInterface{ - public function __construct(private TagAwareAdapter $tagAwareAdapter) + public function __construct(private readonly TagAwareAdapter $tagAwareAdapter) { } @@ -89,7 +89,7 @@ public function testCreateFromDoctrineAnnotation(): void // phpcs:enable $tagAwareAdapter = new TagAwareAdapter(new NullAdapter()); $tagAwareAdapterProvider = new class ($tagAwareAdapter) implements ProviderInterface{ - public function __construct(private TagAwareAdapter $tagAwareAdapter) + public function __construct(private readonly TagAwareAdapter $tagAwareAdapter) { } diff --git a/tests/ResourceStorageTest.php b/tests/ResourceStorageTest.php index 505b8b5d..4ca68b9f 100644 --- a/tests/ResourceStorageTest.php +++ b/tests/ResourceStorageTest.php @@ -20,7 +20,7 @@ public static function getResourceStorageInstance(): ResourceStorage { $tagAwareAdapter = new TagAwareAdapter(new FilesystemAdapter('', 0, __DIR__ . '/tmp')); $tagAwareAdapterProvider = new class ($tagAwareAdapter) implements ProviderInterface{ - public function __construct(private TagAwareAdapter $tagAwareAdapter) + public function __construct(private readonly TagAwareAdapter $tagAwareAdapter) { } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 53b2de3a..f515b932 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,4 +2,4 @@ declare(strict_types=1); -array_map('unlink', glob(__DIR__ . '/tests/tmp/*.php')); // @phpstan-ignore-line +array_map(unlink(...), glob(__DIR__ . '/tests/tmp/*.php')); // @phpstan-ignore-line