From 253c9eeb1a00be3fc8520c0606c54135590d1950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ondr=C3=A1=C4=8Dek?= Date: Fri, 16 Jan 2026 20:41:50 +0100 Subject: [PATCH] Modernize codebase to use PHP 8.2 features MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roman Ondráček --- composer.json | 2 +- src/Cache/Cleaners/LocalFilesystemCleaner.php | 13 ++++-------- src/Cache/Cleaners/MemcachedCleaner.php | 8 +++---- .../Cleaners/NetteCachingStorageCleaner.php | 8 +++---- .../Generators/DiContainersCacheGenerator.php | 12 ++++------- .../LatteTemplatesCacheGenerator.php | 21 ++++++------------- .../AdvancedCache/CacheCleanCommand.php | 9 +++----- src/Command/Cache/CachePurgeCommand.php | 9 +++----- src/Command/Caching/CachingClearCommand.php | 8 +++---- src/Command/DI/DIPurgeCommand.php | 9 +++----- src/Command/Database/BackupCommand.php | 8 +++---- src/Command/Latte/LattePurgeCommand.php | 9 +++----- src/Command/Latte/LatteWarmupCommand.php | 20 +++++------------- src/Command/Router/RouterDumpCommand.php | 8 +++---- .../Security/SecurityPasswordCommand.php | 8 +++---- src/DI/AbstractCompilerExtension.php | 8 +++---- src/DI/ConsoleBridgesExtension.php | 5 ++++- .../Command/Latte/LatteWarmupCommand.phpt | 2 +- 18 files changed, 58 insertions(+), 109 deletions(-) diff --git a/composer.json b/composer.json index a2612a7..9ba2a42 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "require-dev": { "contributte/console": "^0.11.0 || ^0.12.0", - "contributte/phpstan": "^0.1.0", + "contributte/phpstan": "^0.3.1", "contributte/qa": "^0.4.0", "contributte/tester": "^0.4.0", "latte/latte": "^3.0.12", diff --git a/src/Cache/Cleaners/LocalFilesystemCleaner.php b/src/Cache/Cleaners/LocalFilesystemCleaner.php index d68ceb7..156b619 100644 --- a/src/Cache/Cleaners/LocalFilesystemCleaner.php +++ b/src/Cache/Cleaners/LocalFilesystemCleaner.php @@ -9,20 +9,15 @@ class LocalFilesystemCleaner implements ICleaner { - /** @var string[] */ - private array $directories; - - /** @var string[] */ - private array $ignored; - /** * @param string[] $directories * @param string[] $ignored */ - public function __construct(array $directories, array $ignored = []) + public function __construct( + private readonly array $directories, + private readonly array $ignored = [], + ) { - $this->directories = $directories; - $this->ignored = $ignored; } public function getDescription(): string diff --git a/src/Cache/Cleaners/MemcachedCleaner.php b/src/Cache/Cleaners/MemcachedCleaner.php index bcd4e27..4c7c74f 100644 --- a/src/Cache/Cleaners/MemcachedCleaner.php +++ b/src/Cache/Cleaners/MemcachedCleaner.php @@ -10,15 +10,13 @@ class MemcachedCleaner implements ICleaner { - /** @var Memcached[]|Memcache[] */ - private array $memcaches; - /** * @param Memcached[]|Memcache[] $memcaches */ - public function __construct(array $memcaches) + public function __construct( + private readonly array $memcaches, + ) { - $this->memcaches = $memcaches; } public function getDescription(): string diff --git a/src/Cache/Cleaners/NetteCachingStorageCleaner.php b/src/Cache/Cleaners/NetteCachingStorageCleaner.php index eb637e7..24847eb 100644 --- a/src/Cache/Cleaners/NetteCachingStorageCleaner.php +++ b/src/Cache/Cleaners/NetteCachingStorageCleaner.php @@ -10,15 +10,13 @@ class NetteCachingStorageCleaner implements ICleaner { - /** @var Storage[] */ - private array $storages; - /** * @param Storage[] $storages */ - public function __construct(array $storages) + public function __construct( + private readonly array $storages, + ) { - $this->storages = $storages; } public function getDescription(): string diff --git a/src/Cache/Generators/DiContainersCacheGenerator.php b/src/Cache/Generators/DiContainersCacheGenerator.php index 21676c8..72b4a5e 100644 --- a/src/Cache/Generators/DiContainersCacheGenerator.php +++ b/src/Cache/Generators/DiContainersCacheGenerator.php @@ -9,18 +9,14 @@ class DiContainersCacheGenerator implements IGenerator { - /** @var mixed[] */ - private array $config; - - private Configurator $configurator; - /** * @param mixed[] $config */ - public function __construct(array $config, Configurator $configurator) + public function __construct( + private readonly array $config, + private readonly Configurator $configurator, + ) { - $this->config = $config; - $this->configurator = $configurator; } public function getDescription(): string diff --git a/src/Cache/Generators/LatteTemplatesCacheGenerator.php b/src/Cache/Generators/LatteTemplatesCacheGenerator.php index 3a8ee20..7136c27 100644 --- a/src/Cache/Generators/LatteTemplatesCacheGenerator.php +++ b/src/Cache/Generators/LatteTemplatesCacheGenerator.php @@ -12,26 +12,17 @@ class LatteTemplatesCacheGenerator implements IGenerator { - private TemplateFactory $templateFactory; - - /** @var string[] */ - private array $dirs; - - /** @var string[] */ - private array $excludeDirs; - - private ?string $rootDir = null; - /** * @param string[] $dirs * @param string[] $excludeDirs */ - public function __construct(TemplateFactory $templateFactory, array $dirs, array $excludeDirs = [], ?string $rootDir = null) + public function __construct( + private readonly TemplateFactory $templateFactory, + private readonly array $dirs, + private readonly array $excludeDirs = [], + private readonly ?string $rootDir = null, + ) { - $this->templateFactory = $templateFactory; - $this->dirs = $dirs; - $this->excludeDirs = $excludeDirs; - $this->rootDir = $rootDir; } public function getDescription(): string diff --git a/src/Command/AdvancedCache/CacheCleanCommand.php b/src/Command/AdvancedCache/CacheCleanCommand.php index a5ef6f3..bdd9f25 100644 --- a/src/Command/AdvancedCache/CacheCleanCommand.php +++ b/src/Command/AdvancedCache/CacheCleanCommand.php @@ -20,17 +20,14 @@ class CacheCleanCommand extends Command { - /** @var ICleaner[] */ - private array $cleaners = []; - /** * @param ICleaner[] $cleaners */ - public function __construct(array $cleaners) + public function __construct( + private readonly array $cleaners = [], + ) { parent::__construct(); - - $this->cleaners = $cleaners; } protected function configure(): void diff --git a/src/Command/Cache/CachePurgeCommand.php b/src/Command/Cache/CachePurgeCommand.php index 1fdc7f4..9fdf8fe 100644 --- a/src/Command/Cache/CachePurgeCommand.php +++ b/src/Command/Cache/CachePurgeCommand.php @@ -18,17 +18,14 @@ class CachePurgeCommand extends Command { - /** @var string[] */ - private array $dirs; - /** * @param string[] $dirs */ - public function __construct(array $dirs) + public function __construct( + private readonly array $dirs, + ) { parent::__construct(); - - $this->dirs = $dirs; } protected function configure(): void diff --git a/src/Command/Caching/CachingClearCommand.php b/src/Command/Caching/CachingClearCommand.php index 659756b..52dcad3 100644 --- a/src/Command/Caching/CachingClearCommand.php +++ b/src/Command/Caching/CachingClearCommand.php @@ -19,13 +19,11 @@ class CachingClearCommand extends Command { - private Storage $storage; - - public function __construct(Storage $storage) + public function __construct( + private readonly Storage $storage, + ) { parent::__construct(); - - $this->storage = $storage; } protected function configure(): void diff --git a/src/Command/DI/DIPurgeCommand.php b/src/Command/DI/DIPurgeCommand.php index 4c5fe22..5f02388 100644 --- a/src/Command/DI/DIPurgeCommand.php +++ b/src/Command/DI/DIPurgeCommand.php @@ -16,17 +16,14 @@ class DIPurgeCommand extends Command { - /** @var string[] */ - private array $dirs; - /** * @param string[] $dirs */ - public function __construct(array $dirs) + public function __construct( + private readonly array $dirs, + ) { parent::__construct(); - - $this->dirs = $dirs; } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/Command/Database/BackupCommand.php b/src/Command/Database/BackupCommand.php index a09bf4c..f202b10 100644 --- a/src/Command/Database/BackupCommand.php +++ b/src/Command/Database/BackupCommand.php @@ -18,13 +18,11 @@ class BackupCommand extends Command { - private string $backupPath; - - public function __construct(string $backupPath = '') + public function __construct( + private readonly string $backupPath = '', + ) { parent::__construct(); - - $this->backupPath = $backupPath; } protected function configure(): void diff --git a/src/Command/Latte/LattePurgeCommand.php b/src/Command/Latte/LattePurgeCommand.php index 91801af..bcbd55f 100644 --- a/src/Command/Latte/LattePurgeCommand.php +++ b/src/Command/Latte/LattePurgeCommand.php @@ -16,17 +16,14 @@ class LattePurgeCommand extends Command { - /** @var string[] */ - private array $dirs; - /** * @param string[] $dirs */ - public function __construct(array $dirs) + public function __construct( + private readonly array $dirs, + ) { parent::__construct(); - - $this->dirs = $dirs; } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/Command/Latte/LatteWarmupCommand.php b/src/Command/Latte/LatteWarmupCommand.php index b7f0aea..b4d74e5 100644 --- a/src/Command/Latte/LatteWarmupCommand.php +++ b/src/Command/Latte/LatteWarmupCommand.php @@ -5,7 +5,6 @@ use Nette\Bridges\ApplicationLatte\Template; use Nette\Bridges\ApplicationLatte\TemplateFactory; use Nette\Utils\Finder; -use SplFileInfo; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -20,25 +19,17 @@ class LatteWarmupCommand extends Command { - private TemplateFactory $templateFactory; - - /** @var string[] */ - private array $dirs; - - /** @var string[] */ - private array $excludeDirs; - /** * @param string[] $dirs * @param string[] $excludeDirs */ - public function __construct(TemplateFactory $templateFactory, array $dirs, array $excludeDirs = []) + public function __construct( + private readonly TemplateFactory $templateFactory, + private readonly array $dirs, + private readonly array $excludeDirs = [], + ) { parent::__construct(); - - $this->templateFactory = $templateFactory; - $this->dirs = $dirs; - $this->excludeDirs = $excludeDirs; } protected function execute(InputInterface $input, OutputInterface $output): int @@ -58,7 +49,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $stats = ['ok' => 0, 'error' => 0]; - /** @var SplFileInfo $file */ foreach ($finder as $file) { try { $latte->warmupCache($file->getPathname()); diff --git a/src/Command/Router/RouterDumpCommand.php b/src/Command/Router/RouterDumpCommand.php index 89178fb..282648a 100644 --- a/src/Command/Router/RouterDumpCommand.php +++ b/src/Command/Router/RouterDumpCommand.php @@ -20,13 +20,11 @@ final class RouterDumpCommand extends Command { - private Router $router; - - public function __construct(Router $router) + public function __construct( + private readonly Router $router, + ) { parent::__construct(); - - $this->router = $router; } protected function execute(InputInterface $input, OutputInterface $output): int diff --git a/src/Command/Security/SecurityPasswordCommand.php b/src/Command/Security/SecurityPasswordCommand.php index d93ea71..93d37a3 100644 --- a/src/Command/Security/SecurityPasswordCommand.php +++ b/src/Command/Security/SecurityPasswordCommand.php @@ -22,13 +22,11 @@ class SecurityPasswordCommand extends Command { - private Passwords $passwords; - - public function __construct(Passwords $passwords) + public function __construct( + private readonly Passwords $passwords, + ) { parent::__construct(); - - $this->passwords = $passwords; } protected function configure(): void diff --git a/src/DI/AbstractCompilerExtension.php b/src/DI/AbstractCompilerExtension.php index 7bd6413..887db02 100644 --- a/src/DI/AbstractCompilerExtension.php +++ b/src/DI/AbstractCompilerExtension.php @@ -13,15 +13,13 @@ abstract class AbstractCompilerExtension extends CompilerExtension { - protected bool $cliMode; - - public function __construct(bool $cliMode = false) + public function __construct( + protected bool $cliMode = false, + ) { if (func_num_args() <= 0) { throw new LogicalException(sprintf('Provide CLI mode, e.q. %s(%%consoleMode%%).', static::class)); } - - $this->cliMode = $cliMode; } } diff --git a/src/DI/ConsoleBridgesExtension.php b/src/DI/ConsoleBridgesExtension.php index b46536d..f5f9af6 100644 --- a/src/DI/ConsoleBridgesExtension.php +++ b/src/DI/ConsoleBridgesExtension.php @@ -7,6 +7,10 @@ use Nette\Schema\Expect; use Nette\Schema\Schema; +/** + * @property-read array|object|null> $config + * @method array|object|null> getConfig() + */ final class ConsoleBridgesExtension extends AbstractCompilerExtension { @@ -51,7 +55,6 @@ public function loadConfiguration(): void return; } - /** @var mixed[] $config */ $config = $this->config; /** @var false|array|object|null $bridgeConfig */ diff --git a/tests/Cases/Command/Latte/LatteWarmupCommand.phpt b/tests/Cases/Command/Latte/LatteWarmupCommand.phpt index 964b91d..2005ea1 100644 --- a/tests/Cases/Command/Latte/LatteWarmupCommand.phpt +++ b/tests/Cases/Command/Latte/LatteWarmupCommand.phpt @@ -30,7 +30,7 @@ Toolkit::test(function (): void { ); $application = new Application(); - $application->add(new LatteWarmupCommand( + $application->addCommand(new LatteWarmupCommand( $templateFactory, [__DIR__ . '/../../../Fixtures/Latte'] ));