From f6574f6c67be16bd7af09b05cf88d02472c11ffb Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:48:48 +0400 Subject: [PATCH 1/3] [#601] Use first-class callable syntax for function names and drop its Rector skip --- rector.php | 2 -- src/Http/Traits/Request/Body.php | 2 +- src/Mailer/MailTrap.php | 8 ++++---- src/Router/Route.php | 2 +- src/Router/RouteBuilder.php | 2 +- src/Storage/Uploads/UploadPolicy.php | 2 +- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/rector.php b/rector.php index 9920973ba..5775bfb33 100644 --- a/rector.php +++ b/rector.php @@ -4,7 +4,6 @@ use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; -use Rector\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector; use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\LevelSetList; @@ -25,6 +24,5 @@ ->withSkip([ ClassPropertyAssignToConstructorPromotionRector::class, ReadOnlyPropertyRector::class, - FunctionFirstClassCallableRector::class, ArrayToFirstClassCallableRector::class, ]); diff --git a/src/Http/Traits/Request/Body.php b/src/Http/Traits/Request/Body.php index 01fef752c..c39995265 100644 --- a/src/Http/Traits/Request/Body.php +++ b/src/Http/Traits/Request/Body.php @@ -50,7 +50,7 @@ public function get(string $key, ?string $default = null, bool $raw = false) } return is_array($value) - ? array_map('strip_tags', $value) + ? array_map(strip_tags(...), $value) : strip_tags($value); } diff --git a/src/Mailer/MailTrap.php b/src/Mailer/MailTrap.php index 5bb8a9fc6..21de713bb 100644 --- a/src/Mailer/MailTrap.php +++ b/src/Mailer/MailTrap.php @@ -126,7 +126,7 @@ public function getParsedDate(): ?string public function getParsedToAddresses(): array { $addresses = explode(',', $this->message->getHeaderValue('to')); - return array_map('trim', $addresses); + return array_map(trim(...), $addresses); } /** @@ -144,7 +144,7 @@ public function getParsedFromAddress(): ?string public function getParsedCcAddresses(): array { $addresses = explode(',', $this->message->getHeaderValue('cc')); - return array_map('trim', $addresses); + return array_map(trim(...), $addresses); } /** @@ -154,7 +154,7 @@ public function getParsedCcAddresses(): array public function getParsedBccAddresses(): array { $addresses = explode(',', $this->message->getHeaderValue('bcc')); - return array_map('trim', $addresses); + return array_map(trim(...), $addresses); } /** @@ -164,7 +164,7 @@ public function getParsedBccAddresses(): array public function getParsedReplyToAddresses(): array { $addresses = explode(',', $this->message->getHeaderValue('reply-to')); - return array_map('trim', $addresses); + return array_map(trim(...), $addresses); } /** diff --git a/src/Router/Route.php b/src/Router/Route.php index 1c4d7fedb..701f8366c 100644 --- a/src/Router/Route.php +++ b/src/Router/Route.php @@ -93,7 +93,7 @@ public function __construct( throw RouteException::noHttpMethods(); } - $this->methods = array_map('strtoupper', $methods); + $this->methods = array_map(strtoupper(...), $methods); $this->pattern = $pattern; if ($closure !== null) { diff --git a/src/Router/RouteBuilder.php b/src/Router/RouteBuilder.php index cb127e6d6..52dad633a 100644 --- a/src/Router/RouteBuilder.php +++ b/src/Router/RouteBuilder.php @@ -94,7 +94,7 @@ public function build(array $moduleRouteClosures, array $moduleConfigs): RouteCo public function add(string $path, string $methods, $handler, string $action = null): self { $methodList = array_filter( - array_map('trim', explode('|', $methods)), + array_map(trim(...), explode('|', $methods)), static fn ($m): bool => $m !== '' ); diff --git a/src/Storage/Uploads/UploadPolicy.php b/src/Storage/Uploads/UploadPolicy.php index ec4567a34..f5287ae62 100644 --- a/src/Storage/Uploads/UploadPolicy.php +++ b/src/Storage/Uploads/UploadPolicy.php @@ -63,7 +63,7 @@ private function normalize(array $allowedMimeTypes): array foreach ($allowedMimeTypes as $mimeType => $extensions) { $values = is_array($extensions) ? $extensions : [$extensions]; - $normalized[$mimeType] = array_values(array_map('strval', $values)); + $normalized[$mimeType] = array_values(array_map(strval(...), $values)); } return $normalized; From 2773bc1091a830d1202420816e2e8692e3a0d6bc Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:55:22 +0400 Subject: [PATCH 2/3] [#601] Use first-class callable syntax for methods and drop its Rector skip --- rector.php | 2 -- src/Tracer/ErrorHandler.php | 4 ++-- src/Transformer/Transformer.php | 2 +- tests/Unit/Tracer/ErrorHandlerTest.php | 20 ++++++++++++++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/rector.php b/rector.php index 5775bfb33..50c9d10ec 100644 --- a/rector.php +++ b/rector.php @@ -4,7 +4,6 @@ use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; -use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -24,5 +23,4 @@ ->withSkip([ ClassPropertyAssignToConstructorPromotionRector::class, ReadOnlyPropertyRector::class, - ArrayToFirstClassCallableRector::class, ]); diff --git a/src/Tracer/ErrorHandler.php b/src/Tracer/ErrorHandler.php index bef92a4d2..43526c7ba 100644 --- a/src/Tracer/ErrorHandler.php +++ b/src/Tracer/ErrorHandler.php @@ -53,8 +53,8 @@ public function setup(Logger $logger): void { $this->logger = $logger; - set_error_handler([$this, 'handleError']); - set_exception_handler([$this, 'handleException']); + set_error_handler($this->handleError(...)); + set_exception_handler($this->handleException(...)); } public function setCliOutput(OutputInterface $output): void diff --git a/src/Transformer/Transformer.php b/src/Transformer/Transformer.php index 3f6ade08a..1303f3813 100644 --- a/src/Transformer/Transformer.php +++ b/src/Transformer/Transformer.php @@ -25,6 +25,6 @@ class Transformer */ public static function transform(array $data, TransformerInterface $transformer): array { - return array_map([$transformer, 'transform'], $data); + return array_map($transformer->transform(...), $data); } } diff --git a/tests/Unit/Tracer/ErrorHandlerTest.php b/tests/Unit/Tracer/ErrorHandlerTest.php index 6ef78251f..5f57f34f1 100644 --- a/tests/Unit/Tracer/ErrorHandlerTest.php +++ b/tests/Unit/Tracer/ErrorHandlerTest.php @@ -9,9 +9,11 @@ use Quantum\App\Enums\AppType; use Quantum\Logger\Logger; use ReflectionException; +use ReflectionFunction; use ErrorException; use ParseError; use Exception; +use Closure; use Mockery; class ErrorHandlerTest extends AppTestCase @@ -43,9 +45,12 @@ public function testSetupRegistersErrorHandler(): void restore_error_handler(); $this->assertNotNull($currentHandler); - $this->assertIsArray($currentHandler); - $this->assertInstanceOf(ErrorHandler::class, $currentHandler[0]); - $this->assertEquals('handleError', $currentHandler[1]); + $this->assertInstanceOf(Closure::class, $currentHandler); + + $reflection = new ReflectionFunction($currentHandler); + + $this->assertInstanceOf(ErrorHandler::class, $reflection->getClosureThis()); + $this->assertEquals('handleError', $reflection->getName()); } public function testSetupRegistersExceptionHandler(): void @@ -59,9 +64,12 @@ public function testSetupRegistersExceptionHandler(): void restore_exception_handler(); $this->assertNotNull($currentHandler); - $this->assertIsArray($currentHandler); - $this->assertInstanceOf(ErrorHandler::class, $currentHandler[0]); - $this->assertEquals('handleException', $currentHandler[1]); + $this->assertInstanceOf(Closure::class, $currentHandler); + + $reflection = new ReflectionFunction($currentHandler); + + $this->assertInstanceOf(ErrorHandler::class, $reflection->getClosureThis()); + $this->assertEquals('handleException', $reflection->getName()); } public function testHandleErrorThrowsErrorException(): void From 693ffeede26f392a49dc83c689293afd5d27a6ed Mon Sep 17 00:00:00 2001 From: Arman <407448+armanist@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:14:04 +0400 Subject: [PATCH 3/3] [#601] Make constructor-assigned private properties readonly and drop its Rector skip --- rector.php | 2 -- src/App/App.php | 2 +- src/App/AppContext.php | 6 +++--- src/App/Pipeline.php | 4 ++-- src/Archive/Adapters/PharAdapter.php | 2 +- src/Archive/Adapters/ZipAdapter.php | 2 +- src/Archive/Archive.php | 2 +- src/Asset/Asset.php | 10 +++++----- src/Auth/Auth.php | 2 +- src/Cache/Cache.php | 2 +- src/Captcha/Captcha.php | 2 +- src/Cron/CronLock.php | 8 ++++---- src/Cron/CronTask.php | 2 +- src/Cron/Schedule.php | 2 +- src/Csrf/Csrf.php | 4 ++-- src/Database/Schemas/Column.php | 2 +- src/Debugger/Debugger.php | 4 ++-- src/Di/DiContainer.php | 2 +- .../Adapters/SymmetricEncryptionAdapter.php | 2 +- src/Encryption/Cryptor.php | 2 +- src/Jwt/JwtToken.php | 2 +- src/Lang/Lang.php | 2 +- src/Logger/Adapters/MessageAdapter.php | 2 +- src/Logger/Logger.php | 2 +- src/Mailer/MailTrap.php | 6 +++--- src/Mailer/Mailer.php | 2 +- src/Middleware/MiddlewareManager.php | 6 +++--- src/Migration/MigrationManager.php | 8 ++++---- src/Module/ModuleLoader.php | 2 +- src/Module/ModuleManager.php | 14 +++++++------- src/Paginator/Paginator.php | 2 +- .../Adapters/FileRateLimitAdapter.php | 8 ++++---- .../Adapters/RedisRateLimitAdapter.php | 6 +++--- src/RateLimit/RateLimitMiddleware.php | 2 +- src/RateLimit/RateLimiter.php | 2 +- src/Renderer/Renderer.php | 2 +- src/ResourceCache/ViewCache.php | 2 +- src/Router/MatchedRoute.php | 4 ++-- src/Router/RouteBuilder.php | 4 ++-- src/Router/RouteFinder.php | 4 ++-- .../Adapters/Database/DatabaseHandler.php | 2 +- src/Session/Session.php | 2 +- .../Dropbox/DropboxFileSystemAdapter.php | 2 +- .../GoogleDriveFileSystemAdapter.php | 2 +- src/Storage/FileSystem.php | 2 +- src/Storage/Uploads/UploadStorage.php | 2 +- src/Tracer/ErrorHandler.php | 4 ++-- src/Tracer/WebExceptionRenderer.php | 2 +- src/View/View.php | 6 +++--- tests/Unit/Migration/MigrationManagerTest.php | 19 +++++++++++++++---- 50 files changed, 99 insertions(+), 90 deletions(-) diff --git a/rector.php b/rector.php index 50c9d10ec..1cbdfe96b 100644 --- a/rector.php +++ b/rector.php @@ -4,7 +4,6 @@ use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; -use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; use Rector\Config\RectorConfig; @@ -22,5 +21,4 @@ ]) ->withSkip([ ClassPropertyAssignToConstructorPromotionRector::class, - ReadOnlyPropertyRector::class, ]); diff --git a/src/App/App.php b/src/App/App.php index fde9b474b..873a97e70 100644 --- a/src/App/App.php +++ b/src/App/App.php @@ -25,7 +25,7 @@ class App { private static ?AppContext $context = null; - private AppInterface $adapter; + private readonly AppInterface $adapter; public function __construct(AppInterface $adapter) { diff --git a/src/App/AppContext.php b/src/App/AppContext.php index 5ea17b369..4bd5d93c7 100644 --- a/src/App/AppContext.php +++ b/src/App/AppContext.php @@ -25,11 +25,11 @@ */ class AppContext { - private string $baseDir; + private readonly string $baseDir; - private DiContainer $container; + private readonly DiContainer $container; - private string $type; + private readonly string $type; private bool $stopped = false; diff --git a/src/App/Pipeline.php b/src/App/Pipeline.php index 9818ff5c8..99bcd5a29 100644 --- a/src/App/Pipeline.php +++ b/src/App/Pipeline.php @@ -29,12 +29,12 @@ final class Pipeline /** * @var array> */ - private array $stages; + private readonly array $stages; /** * @var StageInterface|null */ - private ?StageInterface $closingStage; + private readonly ?StageInterface $closingStage; /** * @param array> $stages diff --git a/src/Archive/Adapters/PharAdapter.php b/src/Archive/Adapters/PharAdapter.php index 0fc5c763b..6adcf674b 100644 --- a/src/Archive/Adapters/PharAdapter.php +++ b/src/Archive/Adapters/PharAdapter.php @@ -25,7 +25,7 @@ */ class PharAdapter implements ArchiveInterface { - private FileSystem $fs; + private readonly FileSystem $fs; private ?string $archiveName = null; diff --git a/src/Archive/Adapters/ZipAdapter.php b/src/Archive/Adapters/ZipAdapter.php index ace661dd4..c53d87f9e 100644 --- a/src/Archive/Adapters/ZipAdapter.php +++ b/src/Archive/Adapters/ZipAdapter.php @@ -25,7 +25,7 @@ */ class ZipAdapter implements ArchiveInterface { - private FileSystem $fs; + private readonly FileSystem $fs; private ?string $archiveName = null; diff --git a/src/Archive/Archive.php b/src/Archive/Archive.php index a236f3f70..a9db74184 100644 --- a/src/Archive/Archive.php +++ b/src/Archive/Archive.php @@ -30,7 +30,7 @@ */ class Archive { - private ArchiveInterface $adapter; + private readonly ArchiveInterface $adapter; public function __construct(ArchiveInterface $adapter) { diff --git a/src/Asset/Asset.php b/src/Asset/Asset.php index 88bdfaf67..9fc412180 100644 --- a/src/Asset/Asset.php +++ b/src/Asset/Asset.php @@ -29,18 +29,18 @@ class Asset */ public const JS = 2; - private int $type; + private readonly int $type; - private string $path; + private readonly string $path; - private ?string $name; + private readonly ?string $name; /** * @var array|null */ - private ?array $attributes; + private readonly ?array $attributes; - private int $position; + private readonly int $position; /** * Asset templates diff --git a/src/Auth/Auth.php b/src/Auth/Auth.php index 4155e218b..f1ce13ea7 100644 --- a/src/Auth/Auth.php +++ b/src/Auth/Auth.php @@ -24,7 +24,7 @@ */ class Auth { - private AuthenticatableInterface $adapter; + private readonly AuthenticatableInterface $adapter; public function __construct(AuthenticatableInterface $adapter) { diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php index 992aa249b..e8d80fdb3 100644 --- a/src/Cache/Cache.php +++ b/src/Cache/Cache.php @@ -28,7 +28,7 @@ */ class Cache { - private CacheInterface $adapter; + private readonly CacheInterface $adapter; /** * Cache constructor diff --git a/src/Captcha/Captcha.php b/src/Captcha/Captcha.php index d344b088f..e6ea3a23b 100644 --- a/src/Captcha/Captcha.php +++ b/src/Captcha/Captcha.php @@ -26,7 +26,7 @@ */ class Captcha { - private CaptchaInterface $adapter; + private readonly CaptchaInterface $adapter; public function __construct(CaptchaInterface $adapter) { diff --git a/src/Cron/CronLock.php b/src/Cron/CronLock.php index 862f4f449..416785254 100644 --- a/src/Cron/CronLock.php +++ b/src/Cron/CronLock.php @@ -22,18 +22,18 @@ */ class CronLock { - private string $lockDirectory; + private readonly string $lockDirectory; - private string $taskName; + private readonly string $taskName; - private string $lockFile; + private readonly string $lockFile; /** @var resource|null */ private $lockHandle; private bool $ownsLock = false; - private int $maxLockAge; + private readonly int $maxLockAge; private const DEFAULT_MAX_LOCK_AGE = 86400; diff --git a/src/Cron/CronTask.php b/src/Cron/CronTask.php index 4d788e90b..def7647a6 100644 --- a/src/Cron/CronTask.php +++ b/src/Cron/CronTask.php @@ -29,7 +29,7 @@ class CronTask implements CronTaskInterface /** * Task name */ - private string $name; + private readonly string $name; /** * Task callback diff --git a/src/Cron/Schedule.php b/src/Cron/Schedule.php index 965d6c7e6..31e01b54d 100644 --- a/src/Cron/Schedule.php +++ b/src/Cron/Schedule.php @@ -22,7 +22,7 @@ class Schedule /** * Task name */ - private string $name; + private readonly string $name; /** * Cron expression diff --git a/src/Csrf/Csrf.php b/src/Csrf/Csrf.php index d5d192450..1949bd383 100644 --- a/src/Csrf/Csrf.php +++ b/src/Csrf/Csrf.php @@ -35,9 +35,9 @@ class Csrf */ public const TOKEN_KEY = 'csrf-token'; - private Session $storage; + private readonly Session $storage; - private Hasher $hasher; + private readonly Hasher $hasher; /** * @throws ConfigException diff --git a/src/Database/Schemas/Column.php b/src/Database/Schemas/Column.php index a92ac1344..e37585cdb 100644 --- a/src/Database/Schemas/Column.php +++ b/src/Database/Schemas/Column.php @@ -113,7 +113,7 @@ class Column */ public const ATTR_ZEROFILL = 'UNSIGNED ZEROFILL'; - private string $name; + private readonly string $name; private ?string $newName = null; diff --git a/src/Debugger/Debugger.php b/src/Debugger/Debugger.php index 3c6124700..a4765b25d 100644 --- a/src/Debugger/Debugger.php +++ b/src/Debugger/Debugger.php @@ -65,12 +65,12 @@ class Debugger /** * Store */ - private DebuggerStore $store; + private readonly DebuggerStore $store; /** * DebugBar instance */ - private DebugBar $debugBar; + private readonly DebugBar $debugBar; /** * Assets url diff --git a/src/Di/DiContainer.php b/src/Di/DiContainer.php index 658c2ecdb..fb3417e07 100644 --- a/src/Di/DiContainer.php +++ b/src/Di/DiContainer.php @@ -28,7 +28,7 @@ */ class DiContainer { - private DiRegistry $registry; + private readonly DiRegistry $registry; /** * @var array diff --git a/src/Encryption/Adapters/SymmetricEncryptionAdapter.php b/src/Encryption/Adapters/SymmetricEncryptionAdapter.php index 9f08b9066..15c6f2724 100644 --- a/src/Encryption/Adapters/SymmetricEncryptionAdapter.php +++ b/src/Encryption/Adapters/SymmetricEncryptionAdapter.php @@ -27,7 +27,7 @@ class SymmetricEncryptionAdapter implements EncryptionInterface */ public const CIPHER_METHOD = 'aes-256-cbc'; - private string $appKey; + private readonly string $appKey; /** * @throws BaseException|ReflectionException diff --git a/src/Encryption/Cryptor.php b/src/Encryption/Cryptor.php index b38a01b75..26e40016e 100644 --- a/src/Encryption/Cryptor.php +++ b/src/Encryption/Cryptor.php @@ -23,7 +23,7 @@ */ class Cryptor { - private EncryptionInterface $adapter; + private readonly EncryptionInterface $adapter; public function __construct(EncryptionInterface $adapter) { diff --git a/src/Jwt/JwtToken.php b/src/Jwt/JwtToken.php index 6bf8e2c17..2d442d2e4 100644 --- a/src/Jwt/JwtToken.php +++ b/src/Jwt/JwtToken.php @@ -25,7 +25,7 @@ class JwtToken extends JWT /** * JWT secret key */ - private string $key; + private readonly string $key; /** * Encryption algorithm diff --git a/src/Lang/Lang.php b/src/Lang/Lang.php index dc566c1b3..2d6e0c37a 100644 --- a/src/Lang/Lang.php +++ b/src/Lang/Lang.php @@ -22,7 +22,7 @@ class Lang { private ?string $currentLang = null; - private LangAdapterInterface $adapter; + private readonly LangAdapterInterface $adapter; public function __construct(string $lang, LangAdapterInterface $adapter) { diff --git a/src/Logger/Adapters/MessageAdapter.php b/src/Logger/Adapters/MessageAdapter.php index c9e0626b2..1832a3b83 100644 --- a/src/Logger/Adapters/MessageAdapter.php +++ b/src/Logger/Adapters/MessageAdapter.php @@ -28,7 +28,7 @@ class MessageAdapter implements ReportableInterface /** * The number of last messages kept; 0 keeps every message */ - private int $limit; + private readonly int $limit; public function __construct(int $limit = 1000) { diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index b94f6a52f..66a822364 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -21,7 +21,7 @@ */ class Logger implements LoggerInterface { - private ReportableInterface $adapter; + private readonly ReportableInterface $adapter; public function __construct(ReportableInterface $adapter) { diff --git a/src/Mailer/MailTrap.php b/src/Mailer/MailTrap.php index 21de713bb..742964f2e 100644 --- a/src/Mailer/MailTrap.php +++ b/src/Mailer/MailTrap.php @@ -27,16 +27,16 @@ */ class MailTrap { - private FileSystem $fs; + private readonly FileSystem $fs; - private MessageParser $parser; + private readonly MessageParser $parser; /** * @var MessagePart|MessagePartInterface */ private $message; - private string $emailsDirectory; + private readonly string $emailsDirectory; /** * @throws BaseException diff --git a/src/Mailer/Mailer.php b/src/Mailer/Mailer.php index fca072549..fe7bfbed7 100644 --- a/src/Mailer/Mailer.php +++ b/src/Mailer/Mailer.php @@ -32,7 +32,7 @@ */ class Mailer { - private MailerInterface $adapter; + private readonly MailerInterface $adapter; public function __construct(MailerInterface $adapter) { diff --git a/src/Middleware/MiddlewareManager.php b/src/Middleware/MiddlewareManager.php index b57f21242..a989b73b3 100644 --- a/src/Middleware/MiddlewareManager.php +++ b/src/Middleware/MiddlewareManager.php @@ -34,11 +34,11 @@ class MiddlewareManager /** * Current module */ - private ?string $module; + private readonly ?string $module; - private Route $route; + private readonly Route $route; - private bool $hasRateLimit; + private readonly bool $hasRateLimit; public function __construct(MatchedRoute $matchedRoute) { diff --git a/src/Migration/MigrationManager.php b/src/Migration/MigrationManager.php index 0221fc3df..c142cfb9a 100644 --- a/src/Migration/MigrationManager.php +++ b/src/Migration/MigrationManager.php @@ -55,13 +55,13 @@ class MigrationManager */ private array $migrations = []; - private TableFactory $tableFactory; + private readonly TableFactory $tableFactory; - private string $migrationFolder; + private readonly string $migrationFolder; - private FileSystem $fs; + private readonly FileSystem $fs; - private Database $db; + private readonly Database $db; /** * @throws BaseException|ConfigException|DiException|FileSystemException|ReflectionException diff --git a/src/Module/ModuleLoader.php b/src/Module/ModuleLoader.php index 7a57b15eb..fec76cdf3 100644 --- a/src/Module/ModuleLoader.php +++ b/src/Module/ModuleLoader.php @@ -41,7 +41,7 @@ class ModuleLoader /** @var array */ private array $moduleRouteClosures = []; - private FileSystem $fs; + private readonly FileSystem $fs; /** * @throws ModuleException|ConfigException|DiException|BaseException|ReflectionException diff --git a/src/Module/ModuleManager.php b/src/Module/ModuleManager.php index 28b6de818..4c5ffa799 100644 --- a/src/Module/ModuleManager.php +++ b/src/Module/ModuleManager.php @@ -33,19 +33,19 @@ class ModuleManager protected bool $optionEnabled; - private string $moduleName; + private readonly string $moduleName; - private string $template; + private readonly string $template; - private string $modulePath; + private readonly string $modulePath; - private string $assetsPath; + private readonly string $assetsPath; - private string $templatePath; + private readonly string $templatePath; - private bool $withAssets; + private readonly bool $withAssets; - private string $modulesConfigPath; + private readonly string $modulesConfigPath; /** * @throws ConfigException|DiException|BaseException|ReflectionException diff --git a/src/Paginator/Paginator.php b/src/Paginator/Paginator.php index 50a51ab7d..6254c7440 100644 --- a/src/Paginator/Paginator.php +++ b/src/Paginator/Paginator.php @@ -36,7 +36,7 @@ */ class Paginator { - private PaginatorInterface $adapter; + private readonly PaginatorInterface $adapter; public function __construct(PaginatorInterface $adapter) { diff --git a/src/RateLimit/Adapters/FileRateLimitAdapter.php b/src/RateLimit/Adapters/FileRateLimitAdapter.php index 70c23af46..e9cfb9951 100644 --- a/src/RateLimit/Adapters/FileRateLimitAdapter.php +++ b/src/RateLimit/Adapters/FileRateLimitAdapter.php @@ -23,13 +23,13 @@ */ class FileRateLimitAdapter implements RateLimitAdapterInterface { - private FileSystem $fs; + private readonly FileSystem $fs; - private int $resetInterval; + private readonly int $resetInterval; - private string $path; + private readonly string $path; - private string $prefix; + private readonly string $prefix; /** * @param array $params diff --git a/src/RateLimit/Adapters/RedisRateLimitAdapter.php b/src/RateLimit/Adapters/RedisRateLimitAdapter.php index cf1356ce8..24950162f 100644 --- a/src/RateLimit/Adapters/RedisRateLimitAdapter.php +++ b/src/RateLimit/Adapters/RedisRateLimitAdapter.php @@ -20,11 +20,11 @@ */ class RedisRateLimitAdapter implements RateLimitAdapterInterface { - private Redis $redis; + private readonly Redis $redis; - private int $resetInterval; + private readonly int $resetInterval; - private string $prefix; + private readonly string $prefix; /** * @param array $params diff --git a/src/RateLimit/RateLimitMiddleware.php b/src/RateLimit/RateLimitMiddleware.php index b4d30c14f..24aaec861 100644 --- a/src/RateLimit/RateLimitMiddleware.php +++ b/src/RateLimit/RateLimitMiddleware.php @@ -24,7 +24,7 @@ */ class RateLimitMiddleware extends Middleware { - private Route $route; + private readonly Route $route; public function __construct(Route $route) { diff --git a/src/RateLimit/RateLimiter.php b/src/RateLimit/RateLimiter.php index 3c5930777..fec18bd6d 100644 --- a/src/RateLimit/RateLimiter.php +++ b/src/RateLimit/RateLimiter.php @@ -18,7 +18,7 @@ */ class RateLimiter { - private RateLimitAdapterInterface $adapter; + private readonly RateLimitAdapterInterface $adapter; public function __construct(RateLimitAdapterInterface $adapter) { diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php index bf5e5040a..4f090e73a 100644 --- a/src/Renderer/Renderer.php +++ b/src/Renderer/Renderer.php @@ -21,7 +21,7 @@ */ class Renderer { - private TemplateRendererInterface $adapter; + private readonly TemplateRendererInterface $adapter; public function __construct(TemplateRendererInterface $adapter) { diff --git a/src/ResourceCache/ViewCache.php b/src/ResourceCache/ViewCache.php index c7528647a..3bc54e903 100644 --- a/src/ResourceCache/ViewCache.php +++ b/src/ResourceCache/ViewCache.php @@ -36,7 +36,7 @@ class ViewCache private bool $minification = false; - private FileSystem $fs; + private readonly FileSystem $fs; /** * @throws DiException diff --git a/src/Router/MatchedRoute.php b/src/Router/MatchedRoute.php index 47cdd9c78..1c6ea1d93 100644 --- a/src/Router/MatchedRoute.php +++ b/src/Router/MatchedRoute.php @@ -17,12 +17,12 @@ */ final class MatchedRoute { - private Route $route; + private readonly Route $route; /** * @var array */ - private array $params; + private readonly array $params; /** * @param array $params diff --git a/src/Router/RouteBuilder.php b/src/Router/RouteBuilder.php index 52dad633a..c2e1018f8 100644 --- a/src/Router/RouteBuilder.php +++ b/src/Router/RouteBuilder.php @@ -20,9 +20,9 @@ */ final class RouteBuilder { - private RouteCollection $collection; + private readonly RouteCollection $collection; - private PatternCompiler $patternCompiler; + private readonly PatternCompiler $patternCompiler; private ?Route $currentRoute = null; diff --git a/src/Router/RouteFinder.php b/src/Router/RouteFinder.php index f9b1fad33..5f005b4ce 100644 --- a/src/Router/RouteFinder.php +++ b/src/Router/RouteFinder.php @@ -19,9 +19,9 @@ */ final class RouteFinder { - private PatternCompiler $patternCompiler; + private readonly PatternCompiler $patternCompiler; - private RouteCollection $routes; + private readonly RouteCollection $routes; public function __construct(RouteCollection $routes) { diff --git a/src/Session/Adapters/Database/DatabaseHandler.php b/src/Session/Adapters/Database/DatabaseHandler.php index 94f852678..8fd082a59 100644 --- a/src/Session/Adapters/Database/DatabaseHandler.php +++ b/src/Session/Adapters/Database/DatabaseHandler.php @@ -19,7 +19,7 @@ */ class DatabaseHandler implements SessionHandlerInterface { - private DbalInterface $sessionModel; + private readonly DbalInterface $sessionModel; /** * DatabaseHandler constructor. diff --git a/src/Session/Session.php b/src/Session/Session.php index 7ef55f452..1e9ec3f6e 100644 --- a/src/Session/Session.php +++ b/src/Session/Session.php @@ -30,7 +30,7 @@ */ class Session { - private SessionStorageInterface $adapter; + private readonly SessionStorageInterface $adapter; public function __construct(SessionStorageInterface $adapter) { diff --git a/src/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php b/src/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php index a6827bdf5..a70ebbd87 100644 --- a/src/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php +++ b/src/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php @@ -19,7 +19,7 @@ */ class DropboxFileSystemAdapter implements FilesystemAdapterInterface { - private DropboxApp $dropboxApp; + private readonly DropboxApp $dropboxApp; public function __construct(DropboxApp $dropboxApp) { diff --git a/src/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php b/src/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php index a9f6f97e2..d49298298 100644 --- a/src/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php +++ b/src/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php @@ -19,7 +19,7 @@ */ class GoogleDriveFileSystemAdapter implements FilesystemAdapterInterface { - private GoogleDriveApp $googleDriveApp; + private readonly GoogleDriveApp $googleDriveApp; public function __construct(GoogleDriveApp $googleDriveApp) { diff --git a/src/Storage/FileSystem.php b/src/Storage/FileSystem.php index b177b83d7..ccbdc65c3 100644 --- a/src/Storage/FileSystem.php +++ b/src/Storage/FileSystem.php @@ -42,7 +42,7 @@ */ class FileSystem { - private FilesystemAdapterInterface $adapter; + private readonly FilesystemAdapterInterface $adapter; public function __construct(FilesystemAdapterInterface $adapter) { diff --git a/src/Storage/Uploads/UploadStorage.php b/src/Storage/Uploads/UploadStorage.php index 851037aaf..391ac2308 100644 --- a/src/Storage/Uploads/UploadStorage.php +++ b/src/Storage/Uploads/UploadStorage.php @@ -16,7 +16,7 @@ class UploadStorage { - private LocalFilesystemAdapterInterface $localFileSystem; + private readonly LocalFilesystemAdapterInterface $localFileSystem; public function __construct(LocalFilesystemAdapterInterface $localFileSystem) { diff --git a/src/Tracer/ErrorHandler.php b/src/Tracer/ErrorHandler.php index 43526c7ba..726e71a16 100644 --- a/src/Tracer/ErrorHandler.php +++ b/src/Tracer/ErrorHandler.php @@ -31,8 +31,8 @@ class ErrorHandler { private ?Logger $logger = null; private ?OutputInterface $cliOutput = null; - private ExceptionSeverityResolver $severityResolver; - private WebExceptionRenderer $webExceptionRenderer; + private readonly ExceptionSeverityResolver $severityResolver; + private readonly WebExceptionRenderer $webExceptionRenderer; public function __construct( ?ExceptionSeverityResolver $severityResolver = null, diff --git a/src/Tracer/WebExceptionRenderer.php b/src/Tracer/WebExceptionRenderer.php index fa0dec680..76ce82068 100644 --- a/src/Tracer/WebExceptionRenderer.php +++ b/src/Tracer/WebExceptionRenderer.php @@ -19,7 +19,7 @@ class WebExceptionRenderer { - private StackTraceFormatter $stackTraceFormatter; + private readonly StackTraceFormatter $stackTraceFormatter; public function __construct(?StackTraceFormatter $stackTraceFormatter = null) { diff --git a/src/View/View.php b/src/View/View.php index 7945dbeb0..80a22eb15 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -28,11 +28,11 @@ */ class View { - private Renderer $renderer; + private readonly Renderer $renderer; - private AssetManager $assetManager; + private readonly AssetManager $assetManager; - private ViewCache $viewCache; + private readonly ViewCache $viewCache; /** * Layout file diff --git a/tests/Unit/Migration/MigrationManagerTest.php b/tests/Unit/Migration/MigrationManagerTest.php index b4229eb66..48c9e343a 100644 --- a/tests/Unit/Migration/MigrationManagerTest.php +++ b/tests/Unit/Migration/MigrationManagerTest.php @@ -9,6 +9,7 @@ use Quantum\Tests\Unit\AppTestCase; use Quantum\Database\Database; use Quantum\Config\Setup; +use Quantum\Di\Di; use Mockery; class MigrationManagerTest extends AppTestCase @@ -95,11 +96,16 @@ public function testGenerateMigrationCreatesFileAndReturnsMigrationName(): void public function testApplyMigrationsThrowsForUnsupportedDriver(): void { - $manager = new MigrationManager(); + $ormClass = db()->getOrmClass(); + + $this->createContext(); $db = Mockery::mock(Database::class); + $db->shouldReceive('getOrmClass')->andReturn($ormClass); $db->shouldReceive('getConfigs')->andReturn(['driver' => 'sqlserver']); - $this->setPrivateProperty($manager, 'db', $db); + Di::set(Database::class, $db); + + $manager = new MigrationManager(); $this->expectException(MigrationException::class); $this->expectExceptionMessage('The driver `sqlserver` is not supported.'); @@ -109,11 +115,16 @@ public function testApplyMigrationsThrowsForUnsupportedDriver(): void public function testApplyMigrationsThrowsForWrongDirection(): void { - $manager = new MigrationManager(); + $ormClass = db()->getOrmClass(); + + $this->createContext(); $db = Mockery::mock(Database::class); + $db->shouldReceive('getOrmClass')->andReturn($ormClass); $db->shouldReceive('getConfigs')->andReturn(['driver' => 'sqlite']); - $this->setPrivateProperty($manager, 'db', $db); + Di::set(Database::class, $db); + + $manager = new MigrationManager(); $this->expectException(MigrationException::class); $this->expectExceptionMessage('Migration direction can only be [up] or [down]');