From b22a3e993afb50c5197365a8d23dab8b0fc5838f Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Mon, 24 Feb 2025 21:38:06 +0000 Subject: [PATCH] Define property types --- bin/devkit.php | 15 +++------- src/Cli/Application.php | 5 +++- src/Cli/Command/InstallCommand.php | 6 ++-- src/Cli/Command/ListCommand.php | 4 +-- src/Cli/Command/TestCommand.php | 6 ++-- src/Cli/Runner/DryRunner.php | 2 +- src/Cli/ServiceContainer.php | 28 +++++++++++++++-- src/Cli/ServiceContainer/LazyRunner.php | 14 +++++++-- src/Cli/ServiceContainer/RunnerFactory.php | 20 +++++++++++-- src/Json/Factory/Assert.php | 2 +- src/Json/JsonTools.php | 4 +-- src/Runner/ParametrisedRunner.php | 8 ++--- src/Tool/Collection.php | 5 +--- src/Tool/Command/BoxBuildCommand.php | 10 +++---- src/Tool/Command/ComposerBinPluginCommand.php | 6 ++-- .../Command/ComposerBinPluginLinkCommand.php | 6 ++-- .../Command/ComposerGlobalInstallCommand.php | 2 +- .../ComposerGlobalMultiInstallCommand.php | 2 +- src/Tool/Command/ComposerInstallCommand.php | 6 ++-- src/Tool/Command/FileDownloadCommand.php | 4 +-- src/Tool/Command/MultiStepCommand.php | 4 +-- .../OptimisedComposerBinPluginCommand.php | 2 +- src/Tool/Command/PharDownloadCommand.php | 4 +-- src/Tool/Command/PhiveInstallCommand.php | 6 ++-- src/Tool/Command/ShCommand.php | 2 +- src/Tool/Command/TestCommand.php | 4 +-- src/Tool/Filter.php | 4 +-- src/Tool/Tool.php | 12 ++++---- src/Tool/Tools.php | 3 +- src/UseCase/InstallTools.php | 6 ++-- src/UseCase/ListTools.php | 9 +----- src/UseCase/TestTools.php | 2 +- tests/Cli/ApplicationTest.php | 15 ++-------- tests/Cli/Command/InstallCommandTest.php | 12 ++------ tests/Cli/Command/ListCommandTest.php | 5 +--- tests/Cli/Command/TestCommandTest.php | 12 ++------ tests/Cli/Command/ToolboxCommandTestCase.php | 7 ++--- tests/Cli/Runner/DryRunnerTest.php | 12 ++------ tests/Cli/ServiceContainer/LazyRunnerTest.php | 12 ++------ .../ServiceContainer/RunnerFactoryTest.php | 30 +++++-------------- tests/Cli/ServiceContainerTest.php | 7 ++--- tests/Runner/ParametrisedRunnerTest.php | 12 ++------ tests/Tool/CollectionTest.php | 7 +++-- .../Command/ComposerBinPluginCommandTest.php | 5 +--- .../ComposerBinPluginLinkCommandTest.php | 5 +--- .../ComposerGlobalInstallCommandTest.php | 5 +--- .../Tool/Command/FileDownloadCommandTest.php | 5 +--- .../Tool/Command/PharDownloadCommandTest.php | 2 +- .../Tool/Command/PhiveInstallCommandTest.php | 2 +- tests/UseCase/InstallToolsTest.php | 12 ++------ 50 files changed, 168 insertions(+), 212 deletions(-) diff --git a/bin/devkit.php b/bin/devkit.php index fac9276b..8201017e 100755 --- a/bin/devkit.php +++ b/bin/devkit.php @@ -42,9 +42,6 @@ private function toolsJsonDefault(): array ]; } - /** - * @return Collection|Tool[] - */ private function loadTools($jsonPath, ?Filter $filter = null): Collection { return (new JsonTools(function () use ($jsonPath) { @@ -59,7 +56,7 @@ private function loadTools($jsonPath, ?Filter $filter = null): Collection { use Tools; - protected function configure() + protected function configure(): void { $this->setName('update:readme'); $this->setDescription('Updates README.md with latest list of available tools'); @@ -105,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int { use Tools; - protected function configure() + protected function configure(): void { $this->setName('update:phars'); $this->setDescription('Attempts to update phar links to latest versions'); @@ -125,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - private function updatePhars(string $jsonPath, OutputInterface $output) + private function updatePhars(string $jsonPath, OutputInterface $output): int { $phars = $this->findLatestPhars($jsonPath); @@ -192,7 +189,7 @@ function (string $phar) { { use Tools; - protected function configure() + protected function configure(): void { $this->setName('generate:html'); $this->setDescription('Generates an html list of available tools'); @@ -241,10 +238,6 @@ private function toolToHtml(): \Closure }; } - /** - * @param Collection|string[] $toolsHtml - * @return string - */ private function renderPage(Collection $toolsHtml): string { $template = <<<'TEMPLATE' diff --git a/src/Cli/Application.php b/src/Cli/Application.php index 7f254328..8078230e 100644 --- a/src/Cli/Application.php +++ b/src/Cli/Application.php @@ -16,7 +16,7 @@ final class Application extends CliApplication { - private $serviceContainer; + private ServiceContainer $serviceContainer; public function __construct(string $version, ServiceContainer $serviceContainer) { @@ -27,6 +27,9 @@ public function __construct(string $version, ServiceContainer $serviceContainer) $this->setCommandLoader($this->createCommandLoader($serviceContainer)); } + /** + * @throws \Throwable + */ public function doRun(InputInterface $input, OutputInterface $output): int { $this->serviceContainer->set(InputInterface::class, $input); diff --git a/src/Cli/Command/InstallCommand.php b/src/Cli/Command/InstallCommand.php index f6c53fc9..6c5ab9e7 100644 --- a/src/Cli/Command/InstallCommand.php +++ b/src/Cli/Command/InstallCommand.php @@ -17,8 +17,8 @@ final class InstallCommand extends Command public const NAME = 'install'; - private $useCase; - private $runner; + private InstallTools $useCase; + private Runner $runner; public function __construct(InstallTools $useCase, Runner $runner) { @@ -28,7 +28,7 @@ public function __construct(InstallTools $useCase, Runner $runner) $this->runner = $runner; } - protected function configure() + protected function configure(): void { $this->setDescription('Installs tools'); $this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it'); diff --git a/src/Cli/Command/ListCommand.php b/src/Cli/Command/ListCommand.php index 7d3ea273..d29a35aa 100644 --- a/src/Cli/Command/ListCommand.php +++ b/src/Cli/Command/ListCommand.php @@ -18,7 +18,7 @@ final class ListCommand extends Command public const NAME = 'list-tools'; - private $listTools; + private ListTools $listTools; public function __construct(ListTools $listTools) { @@ -27,7 +27,7 @@ public function __construct(ListTools $listTools) $this->listTools = $listTools; } - protected function configure() + protected function configure(): void { $this->setDescription('Lists available tools'); $this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag()); diff --git a/src/Cli/Command/TestCommand.php b/src/Cli/Command/TestCommand.php index 1443a65a..71169915 100644 --- a/src/Cli/Command/TestCommand.php +++ b/src/Cli/Command/TestCommand.php @@ -17,8 +17,8 @@ final class TestCommand extends Command public const NAME = 'test'; - private $useCase; - private $runner; + private TestTools $useCase; + private Runner $runner; public function __construct(TestTools $useCase, Runner $runner) { @@ -28,7 +28,7 @@ public function __construct(TestTools $useCase, Runner $runner) $this->runner = $runner; } - protected function configure() + protected function configure(): void { $this->setDescription('Runs basic tests to verify tools are installed'); $this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it'); diff --git a/src/Cli/Runner/DryRunner.php b/src/Cli/Runner/DryRunner.php index 244ca609..109fb508 100644 --- a/src/Cli/Runner/DryRunner.php +++ b/src/Cli/Runner/DryRunner.php @@ -8,7 +8,7 @@ final class DryRunner implements Runner { - private $output; + private OutputInterface $output; public function __construct(OutputInterface $output) { diff --git a/src/Cli/ServiceContainer.php b/src/Cli/ServiceContainer.php index 11996ec7..655005fd 100644 --- a/src/Cli/ServiceContainer.php +++ b/src/Cli/ServiceContainer.php @@ -22,7 +22,7 @@ class ServiceContainer implements ContainerInterface { - private $services = [ + private array $services = [ InstallCommand::class => 'createInstallCommand', ListCommand::class => 'createListCommand', TestCommand::class => 'createTestCommand', @@ -33,7 +33,7 @@ class ServiceContainer implements ContainerInterface Tools::class => 'createTools', ]; - private $runtimeServices = [ + private array $runtimeServices = [ InputInterface::class => null, OutputInterface::class => null, ]; @@ -73,16 +73,28 @@ public function has(string $id): bool return isset($this->services[$id]) || isset($this->runtimeServices[$id]); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function createInstallCommand(): InstallCommand { return new InstallCommand($this->get(InstallTools::class), $this->get(Runner::class)); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function createListCommand(): ListCommand { return new ListCommand($this->get(ListTools::class)); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function createTestCommand(): TestCommand { return new TestCommand($this->get(TestTools::class), $this->get(Runner::class)); @@ -93,16 +105,28 @@ private function createRunner(): Runner return new LazyRunner(new RunnerFactory($this)); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function createInstallToolsUseCase(): InstallTools { return new InstallTools($this->get(Tools::class)); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function createListToolsUseCase(): ListTools { return new ListTools($this->get(Tools::class)); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function createTestToolsUseCase(): TestTools { return new TestTools($this->get(Tools::class)); diff --git a/src/Cli/ServiceContainer/LazyRunner.php b/src/Cli/ServiceContainer/LazyRunner.php index b2ce407a..8f49a285 100644 --- a/src/Cli/ServiceContainer/LazyRunner.php +++ b/src/Cli/ServiceContainer/LazyRunner.php @@ -2,25 +2,35 @@ namespace Zalas\Toolbox\Cli\ServiceContainer; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Zalas\Toolbox\Runner\Runner; use Zalas\Toolbox\Tool\Command; final class LazyRunner implements Runner { - private $runner; + private ?Runner $runner = null; - private $factory; + private RunnerFactory $factory; public function __construct(RunnerFactory $factory) { $this->factory = $factory; } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ public function run(Command $command): int { return $this->runner()->run($command); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function runner(): Runner { if (null === $this->runner) { diff --git a/src/Cli/ServiceContainer/RunnerFactory.php b/src/Cli/ServiceContainer/RunnerFactory.php index 225c2151..8056c420 100644 --- a/src/Cli/ServiceContainer/RunnerFactory.php +++ b/src/Cli/ServiceContainer/RunnerFactory.php @@ -4,6 +4,7 @@ use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Zalas\Toolbox\Cli\Runner\DryRunner; @@ -13,13 +14,17 @@ class RunnerFactory { - private $container; + private ContainerInterface $container; public function __construct(ContainerInterface $container) { $this->container = $container; } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ public function createRunner(): Runner { $runner = $this->createRealRunner(); @@ -32,9 +37,10 @@ public function createRunner(): Runner } /** - * @return DryRunner|PassthruRunner + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - private function createRealRunner() + private function createRealRunner(): DryRunner|PassthruRunner { if ($this->container->get(InputInterface::class)->getOption('dry-run')) { return new DryRunner($this->container->get(OutputInterface::class)); @@ -43,6 +49,10 @@ private function createRealRunner() return new PassthruRunner(); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function parameters(): array { if ($targetDir = $this->targetDir()) { @@ -52,6 +62,10 @@ private function parameters(): array return []; } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ private function targetDir(): ?string { if (!$this->container->get(InputInterface::class)->hasOption('target-dir')) { diff --git a/src/Json/Factory/Assert.php b/src/Json/Factory/Assert.php index 1ff0a1e6..105becfe 100644 --- a/src/Json/Factory/Assert.php +++ b/src/Json/Factory/Assert.php @@ -4,7 +4,7 @@ final class Assert { - public static function requireFields(array $fields, array $data, string $type) + public static function requireFields(array $fields, array $data, string $type): void { $missingFields = \array_filter($fields, function (string $field) use ($data) { return !isset($data[$field]); diff --git a/src/Json/JsonTools.php b/src/Json/JsonTools.php index c33f51fa..ad5ff1a4 100644 --- a/src/Json/JsonTools.php +++ b/src/Json/JsonTools.php @@ -7,7 +7,6 @@ use Zalas\Toolbox\Json\Factory\ToolFactory; use Zalas\Toolbox\Tool\Collection; use Zalas\Toolbox\Tool\Filter; -use Zalas\Toolbox\Tool\Tool; use Zalas\Toolbox\Tool\Tools; final class JsonTools implements Tools @@ -23,7 +22,8 @@ public function __construct(callable $resourceLocator) } /** - * @return Collection|Tool[] + * @param Filter $filter + * @return Collection */ public function all(Filter $filter): Collection { diff --git a/src/Runner/ParametrisedRunner.php b/src/Runner/ParametrisedRunner.php index 1f6ec049..b73a8f43 100644 --- a/src/Runner/ParametrisedRunner.php +++ b/src/Runner/ParametrisedRunner.php @@ -6,8 +6,8 @@ final class ParametrisedRunner implements Runner { - private $decoratedRunner; - private $parameters; + private Runner $decoratedRunner; + private array $parameters; public function __construct(Runner $decoratedRunner, array $parameters) { @@ -18,8 +18,8 @@ public function __construct(Runner $decoratedRunner, array $parameters) public function run(Command $command): int { return $this->decoratedRunner->run(new class($command, $this->parameters) implements Command { - private $command; - private $parameters; + private Command $command; + private array $parameters; public function __construct(Command $command, array $parameters) { diff --git a/src/Tool/Collection.php b/src/Tool/Collection.php index 0405da25..54939457 100644 --- a/src/Tool/Collection.php +++ b/src/Tool/Collection.php @@ -8,10 +8,7 @@ class Collection implements IteratorAggregate, Countable { - /** - * @var array - */ - private $elements; + private array $elements; private function __construct(array $elements) { diff --git a/src/Tool/Command/BoxBuildCommand.php b/src/Tool/Command/BoxBuildCommand.php index d2e0e8ce..547a4179 100644 --- a/src/Tool/Command/BoxBuildCommand.php +++ b/src/Tool/Command/BoxBuildCommand.php @@ -6,11 +6,11 @@ final class BoxBuildCommand implements Command { - private $repository; - private $phar; - private $bin; - private $workDir; - private $version; + private string $repository; + private string $phar; + private string $bin; + private string $workDir; + private ?string $version; public function __construct(string $repository, string $phar, string $bin, string $workDir, ?string $version = null) { diff --git a/src/Tool/Command/ComposerBinPluginCommand.php b/src/Tool/Command/ComposerBinPluginCommand.php index de66ceaa..0a2986c4 100644 --- a/src/Tool/Command/ComposerBinPluginCommand.php +++ b/src/Tool/Command/ComposerBinPluginCommand.php @@ -7,11 +7,11 @@ final class ComposerBinPluginCommand implements Command { - private $package; + private string $package; - private $namespace; + private string $namespace; - private $links; + private Collection $links; public function __construct(string $package, string $namespace, Collection $links) { diff --git a/src/Tool/Command/ComposerBinPluginLinkCommand.php b/src/Tool/Command/ComposerBinPluginLinkCommand.php index cb2cd99e..4587f526 100644 --- a/src/Tool/Command/ComposerBinPluginLinkCommand.php +++ b/src/Tool/Command/ComposerBinPluginLinkCommand.php @@ -6,9 +6,9 @@ final class ComposerBinPluginLinkCommand implements Command { - private $source; - private $target; - private $namespace; + private string $source; + private string $target; + private string $namespace; public function __construct(string $source, string $target, string $namespace) { diff --git a/src/Tool/Command/ComposerGlobalInstallCommand.php b/src/Tool/Command/ComposerGlobalInstallCommand.php index 1fef35c4..70f3bd7d 100644 --- a/src/Tool/Command/ComposerGlobalInstallCommand.php +++ b/src/Tool/Command/ComposerGlobalInstallCommand.php @@ -6,7 +6,7 @@ final class ComposerGlobalInstallCommand implements Command { - private $package; + private string $package; public function __construct(string $package) { diff --git a/src/Tool/Command/ComposerGlobalMultiInstallCommand.php b/src/Tool/Command/ComposerGlobalMultiInstallCommand.php index 1a2b1e70..7ee962f2 100644 --- a/src/Tool/Command/ComposerGlobalMultiInstallCommand.php +++ b/src/Tool/Command/ComposerGlobalMultiInstallCommand.php @@ -8,7 +8,7 @@ final class ComposerGlobalMultiInstallCommand implements Command { - private $commands; + private Collection $commands; public function __construct(Collection $commands) { diff --git a/src/Tool/Command/ComposerInstallCommand.php b/src/Tool/Command/ComposerInstallCommand.php index 519c04c7..74f0840c 100644 --- a/src/Tool/Command/ComposerInstallCommand.php +++ b/src/Tool/Command/ComposerInstallCommand.php @@ -6,9 +6,9 @@ final class ComposerInstallCommand implements Command { - private $repository; - private $targetDir; - private $version; + private string $repository; + private string $targetDir; + private ?string $version; public function __construct(string $repository, string $targetDir, ?string $version = null) { diff --git a/src/Tool/Command/FileDownloadCommand.php b/src/Tool/Command/FileDownloadCommand.php index 9b910f43..610b380b 100644 --- a/src/Tool/Command/FileDownloadCommand.php +++ b/src/Tool/Command/FileDownloadCommand.php @@ -6,8 +6,8 @@ final class FileDownloadCommand implements Command { - private $url; - private $file; + private string $url; + private string $file; public function __construct(string $url, string $file) { diff --git a/src/Tool/Command/MultiStepCommand.php b/src/Tool/Command/MultiStepCommand.php index 57631716..1ef8ddca 100644 --- a/src/Tool/Command/MultiStepCommand.php +++ b/src/Tool/Command/MultiStepCommand.php @@ -8,8 +8,8 @@ final class MultiStepCommand implements Command { - private $commands; - private $glue; + private Collection $commands; + private mixed $glue; public function __construct(Collection $commands, $glue = ' && ') { diff --git a/src/Tool/Command/OptimisedComposerBinPluginCommand.php b/src/Tool/Command/OptimisedComposerBinPluginCommand.php index e7d0c62a..78d23dc5 100644 --- a/src/Tool/Command/OptimisedComposerBinPluginCommand.php +++ b/src/Tool/Command/OptimisedComposerBinPluginCommand.php @@ -8,7 +8,7 @@ final class OptimisedComposerBinPluginCommand implements Command { - private $commands; + private Collection $commands; public function __construct(Collection $commands) { diff --git a/src/Tool/Command/PharDownloadCommand.php b/src/Tool/Command/PharDownloadCommand.php index 80375416..92a35323 100644 --- a/src/Tool/Command/PharDownloadCommand.php +++ b/src/Tool/Command/PharDownloadCommand.php @@ -6,8 +6,8 @@ final class PharDownloadCommand implements Command { - private $phar; - private $bin; + private string $phar; + private string $bin; public function __construct(string $phar, string $bin) { diff --git a/src/Tool/Command/PhiveInstallCommand.php b/src/Tool/Command/PhiveInstallCommand.php index 790cad0f..e0dbf448 100644 --- a/src/Tool/Command/PhiveInstallCommand.php +++ b/src/Tool/Command/PhiveInstallCommand.php @@ -6,9 +6,9 @@ final class PhiveInstallCommand implements Command { - private $alias; - private $bin; - private $sig; + private string $alias; + private string $bin; + private ?string $sig; public function __construct(string $alias, string $bin, ?string $sig = null) { diff --git a/src/Tool/Command/ShCommand.php b/src/Tool/Command/ShCommand.php index f2b058e5..0e8acc5d 100644 --- a/src/Tool/Command/ShCommand.php +++ b/src/Tool/Command/ShCommand.php @@ -6,7 +6,7 @@ final class ShCommand implements Command { - private $command; + private string $command; public function __construct(string $command) { diff --git a/src/Tool/Command/TestCommand.php b/src/Tool/Command/TestCommand.php index 2c539b9d..2b591cf5 100644 --- a/src/Tool/Command/TestCommand.php +++ b/src/Tool/Command/TestCommand.php @@ -6,8 +6,8 @@ final class TestCommand implements Command { - private $command; - private $name; + private string $command; + private string $name; public function __construct(string $command, string $name) { diff --git a/src/Tool/Filter.php b/src/Tool/Filter.php index afcbcb67..84341616 100644 --- a/src/Tool/Filter.php +++ b/src/Tool/Filter.php @@ -7,12 +7,12 @@ class Filter /** * @var string[] */ - private $excludedTags; + private array $excludedTags; /** * @var string[] */ - private $tags; + private array $tags; /** * @param string[] $excludedTags diff --git a/src/Tool/Tool.php b/src/Tool/Tool.php index d7033b3e..b1b019ae 100644 --- a/src/Tool/Tool.php +++ b/src/Tool/Tool.php @@ -4,12 +4,12 @@ class Tool { - private $name; - private $summary; - private $website; - private $command; - private $testCommand; - private $tags; + private string $name; + private string $summary; + private string $website; + private Command $command; + private Command $testCommand; + private array $tags; public function __construct(string $name, string $summary, string $website, array $tags, Command $command, Command $testCommand) { diff --git a/src/Tool/Tools.php b/src/Tool/Tools.php index 99b5d15f..eb38e49f 100644 --- a/src/Tool/Tools.php +++ b/src/Tool/Tools.php @@ -7,7 +7,8 @@ interface Tools { /** - * @return Collection|Tool[] + * @param Filter $filter + * @return Collection * @throws RuntimeException in case tools cannot be loaded */ public function all(Filter $filter): Collection; diff --git a/src/UseCase/InstallTools.php b/src/UseCase/InstallTools.php index 5b49fe64..4fdf7071 100644 --- a/src/UseCase/InstallTools.php +++ b/src/UseCase/InstallTools.php @@ -24,7 +24,7 @@ class InstallTools { public const PRE_INSTALLATION_TAG = 'pre-installation'; - private $tools; + private Tools $tools; public function __construct(Tools $tools) { @@ -60,7 +60,7 @@ private function commandFilter(Collection $commands): Closure }; } - private function installationCommands(Collection $tools) + private function installationCommands(Collection $tools): Collection { return $tools->filter(function (Tool $tool) { return \in_array(self::PRE_INSTALLATION_TAG, $tool->tags()); @@ -69,7 +69,7 @@ private function installationCommands(Collection $tools) }); } - private function toolCommands(Collection $tools) + private function toolCommands(Collection $tools): Collection { return $tools->filter(function (Tool $tool) { return !\in_array(self::PRE_INSTALLATION_TAG, $tool->tags()); diff --git a/src/UseCase/ListTools.php b/src/UseCase/ListTools.php index 04f1ab93..7f761c52 100644 --- a/src/UseCase/ListTools.php +++ b/src/UseCase/ListTools.php @@ -4,24 +4,17 @@ use Zalas\Toolbox\Tool\Collection; use Zalas\Toolbox\Tool\Filter; -use Zalas\Toolbox\Tool\Tool; use Zalas\Toolbox\Tool\Tools; class ListTools { - /** - * @var Tools - */ - private $tools; + private Tools $tools; public function __construct(Tools $tools) { $this->tools = $tools; } - /** - * @return Collection|Tool[] - */ public function __invoke(Filter $filter): Collection { return $this->tools->all($filter); diff --git a/src/UseCase/TestTools.php b/src/UseCase/TestTools.php index 4c255bbe..64681137 100644 --- a/src/UseCase/TestTools.php +++ b/src/UseCase/TestTools.php @@ -10,7 +10,7 @@ class TestTools { - private $tools; + private Tools $tools; public function __construct(Tools $tools) { diff --git a/tests/Cli/ApplicationTest.php b/tests/Cli/ApplicationTest.php index 7963c001..a880c033 100644 --- a/tests/Cli/ApplicationTest.php +++ b/tests/Cli/ApplicationTest.php @@ -2,7 +2,6 @@ namespace Zalas\Toolbox\Tests\Cli; -use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application as CliApplication; use Symfony\Component\Console\Input\ArrayInput; @@ -18,20 +17,12 @@ class ApplicationTest extends TestCase { private const VERSION = 'test'; - /** - * @var Application - */ - private $app; - - /** - * @var ServiceContainer|Stub - */ - private $container; + private Application $app; protected function setUp(): void { - $this->container = $this->createStub(ServiceContainer::class); - $this->app = new Application(self::VERSION, $this->container); + $container = $this->createStub(ServiceContainer::class); + $this->app = new Application(self::VERSION, $container); } public function test_it_is_a_cli_application() diff --git a/tests/Cli/Command/InstallCommandTest.php b/tests/Cli/Command/InstallCommandTest.php index 227fa937..2081e852 100644 --- a/tests/Cli/Command/InstallCommandTest.php +++ b/tests/Cli/Command/InstallCommandTest.php @@ -15,15 +15,9 @@ class InstallCommandTest extends ToolboxCommandTestCase { protected const CLI_COMMAND_NAME = InstallCommand::NAME; - /** - * @var Runner|Stub - */ - private $runner; - - /** - * @var InstallTools|Stub - */ - private $useCase; + private Runner|Stub $runner; + + private InstallTools|Stub $useCase; protected function setUp(): void { diff --git a/tests/Cli/Command/ListCommandTest.php b/tests/Cli/Command/ListCommandTest.php index 1d7142de..8195b76c 100644 --- a/tests/Cli/Command/ListCommandTest.php +++ b/tests/Cli/Command/ListCommandTest.php @@ -16,10 +16,7 @@ class ListCommandTest extends ToolboxCommandTestCase { protected const CLI_COMMAND_NAME = ListCommand::NAME; - /** - * @var ListTools|Stub - */ - private $useCase; + private ListTools|Stub $useCase; protected function setUp(): void { diff --git a/tests/Cli/Command/TestCommandTest.php b/tests/Cli/Command/TestCommandTest.php index d2198692..1f8b5a2b 100644 --- a/tests/Cli/Command/TestCommandTest.php +++ b/tests/Cli/Command/TestCommandTest.php @@ -15,15 +15,9 @@ class TestCommandTest extends ToolboxCommandTestCase { protected const CLI_COMMAND_NAME = TestCommand::NAME; - /** - * @var Runner|Stub - */ - private $runner; - - /** - * @var TestTools|Stub - */ - private $useCase; + private Runner|Stub $runner; + + private TestTools|Stub $useCase; protected function setUp(): void { diff --git a/tests/Cli/Command/ToolboxCommandTestCase.php b/tests/Cli/Command/ToolboxCommandTestCase.php index b186549c..0b1b24cf 100644 --- a/tests/Cli/Command/ToolboxCommandTestCase.php +++ b/tests/Cli/Command/ToolboxCommandTestCase.php @@ -12,10 +12,7 @@ abstract class ToolboxCommandTestCase extends TestCase { protected const CLI_COMMAND_NAME = ''; - /** - * @var Application - */ - protected $app; + protected Application $app; protected function setUp(): void { @@ -48,7 +45,7 @@ protected function cliCommand(): Command private function createServiceContainer(): ServiceContainer { return new class($this->getContainerTestDoubles()) extends ServiceContainer { - private $services; + private array $services; public function __construct(array $services) { diff --git a/tests/Cli/Runner/DryRunnerTest.php b/tests/Cli/Runner/DryRunnerTest.php index 032ea609..719a8730 100644 --- a/tests/Cli/Runner/DryRunnerTest.php +++ b/tests/Cli/Runner/DryRunnerTest.php @@ -11,15 +11,9 @@ class DryRunnerTest extends TestCase { - /** - * @var DryRunner - */ - private $runner; - - /** - * @var OutputInterface|MockObject - */ - private $out; + private DryRunner $runner; + + private OutputInterface|MockObject $out; protected function setUp(): void { diff --git a/tests/Cli/ServiceContainer/LazyRunnerTest.php b/tests/Cli/ServiceContainer/LazyRunnerTest.php index 4144b012..de7dd73a 100644 --- a/tests/Cli/ServiceContainer/LazyRunnerTest.php +++ b/tests/Cli/ServiceContainer/LazyRunnerTest.php @@ -11,15 +11,9 @@ class LazyRunnerTest extends TestCase { - /** - * @var LazyRunner - */ - private $lazyRunner; - - /** - * @var RunnerFactory|MockObject - */ - private $factory; + private LazyRunner $lazyRunner; + + private RunnerFactory|MockObject $factory; protected function setUp(): void { diff --git a/tests/Cli/ServiceContainer/RunnerFactoryTest.php b/tests/Cli/ServiceContainer/RunnerFactoryTest.php index af3c75ef..27e75d6c 100644 --- a/tests/Cli/ServiceContainer/RunnerFactoryTest.php +++ b/tests/Cli/ServiceContainer/RunnerFactoryTest.php @@ -19,34 +19,20 @@ class RunnerFactoryTest extends TestCase { - /** - * @var ContainerInterface - */ - private $container; - - /** - * @var RunnerFactory - */ - private $runnerFactory; - - /** - * @var InputInterface - */ - private $input; - - /** - * @var OutputInterface|MockObject - */ - private $output; + private RunnerFactory $runnerFactory; + + private InputInterface $input; + + private OutputInterface|MockObject $output; protected function setUp(): void { $this->input = $this->givenInput([]); $this->output = $this->createMock(OutputInterface::class); - $this->container = new class([ InputInterface::class => &$this->input, OutputInterface::class => &$this->output, ]) implements ContainerInterface { + $container = new class([ InputInterface::class => &$this->input, OutputInterface::class => &$this->output, ]) implements ContainerInterface { - public function __construct(private array $services) + public function __construct(private readonly array $services) { } @@ -61,7 +47,7 @@ public function has(string $id): bool } }; - $this->runnerFactory = new RunnerFactory($this->container); + $this->runnerFactory = new RunnerFactory($container); } public function test_it_creates_the_passthru_runner_by_default() diff --git a/tests/Cli/ServiceContainerTest.php b/tests/Cli/ServiceContainerTest.php index 56260c52..0667fd23 100644 --- a/tests/Cli/ServiceContainerTest.php +++ b/tests/Cli/ServiceContainerTest.php @@ -18,10 +18,7 @@ class ServiceContainerTest extends TestCase { - /** - * @var ServiceContainer - */ - private $container; + private ServiceContainer $container; protected function setUp(): void { @@ -47,7 +44,7 @@ public function test_it_creates_application_services(string $serviceId, string $ $this->assertInstanceOf($expectedType, $this->container->get($serviceId)); } - public static function provideApplicationServices() + public static function provideApplicationServices(): \Generator { yield [InstallCommand::class, InstallCommand::class]; yield [ListCommand::class, ListCommand::class]; diff --git a/tests/Runner/ParametrisedRunnerTest.php b/tests/Runner/ParametrisedRunnerTest.php index c3934540..17a11464 100644 --- a/tests/Runner/ParametrisedRunnerTest.php +++ b/tests/Runner/ParametrisedRunnerTest.php @@ -11,15 +11,9 @@ class ParametrisedRunnerTest extends TestCase { - /** - * @var ParametrisedRunner - */ - private $runner; - - /** - * @var Runner|Stub - */ - private $decoratedRunner; + private ParametrisedRunner $runner; + + private Runner|Stub $decoratedRunner; protected function setUp(): void { diff --git a/tests/Tool/CollectionTest.php b/tests/Tool/CollectionTest.php index c524b4aa..48b24d3e 100644 --- a/tests/Tool/CollectionTest.php +++ b/tests/Tool/CollectionTest.php @@ -1,8 +1,9 @@ assertIterates(['ab', 'c', 'aa', 'aaa'], $c, 'The original collection is not modified'); } - private function assertIterates(array $elements, Collection $c) + private function assertIterates(array $elements, Collection $c, string $message = ''): void { - $this->assertSame($elements, \iterator_to_array($c)); + $this->assertSame($elements, \iterator_to_array($c), $message); } } diff --git a/tests/Tool/Command/ComposerBinPluginCommandTest.php b/tests/Tool/Command/ComposerBinPluginCommandTest.php index 4566939e..39d90946 100644 --- a/tests/Tool/Command/ComposerBinPluginCommandTest.php +++ b/tests/Tool/Command/ComposerBinPluginCommandTest.php @@ -13,10 +13,7 @@ class ComposerBinPluginCommandTest extends TestCase private const PACKAGE = 'phpstan/phpstan'; private const NAMESPACE = 'tools'; - /** - * @var ComposerBinPluginCommand - */ - private $command; + private ComposerBinPluginCommand $command; protected function setUp(): void { diff --git a/tests/Tool/Command/ComposerBinPluginLinkCommandTest.php b/tests/Tool/Command/ComposerBinPluginLinkCommandTest.php index d360d5c4..9ded7fc8 100644 --- a/tests/Tool/Command/ComposerBinPluginLinkCommandTest.php +++ b/tests/Tool/Command/ComposerBinPluginLinkCommandTest.php @@ -12,10 +12,7 @@ final class ComposerBinPluginLinkCommandTest extends TestCase private const TARGET = '/tools/churn'; private const NAMESPACE = 'tools'; - /** - * @var ComposerBinPluginLinkCommand - */ - private $command; + private ComposerBinPluginLinkCommand $command; protected function setUp(): void { diff --git a/tests/Tool/Command/ComposerGlobalInstallCommandTest.php b/tests/Tool/Command/ComposerGlobalInstallCommandTest.php index 748d17ee..33d5ace7 100644 --- a/tests/Tool/Command/ComposerGlobalInstallCommandTest.php +++ b/tests/Tool/Command/ComposerGlobalInstallCommandTest.php @@ -10,10 +10,7 @@ class ComposerGlobalInstallCommandTest extends TestCase { private const PACKAGE = 'phan/phan'; - /** - * @var ComposerGlobalInstallCommand - */ - private $command; + private ComposerGlobalInstallCommand $command; protected function setUp(): void { diff --git a/tests/Tool/Command/FileDownloadCommandTest.php b/tests/Tool/Command/FileDownloadCommandTest.php index a155f7d5..25a29421 100644 --- a/tests/Tool/Command/FileDownloadCommandTest.php +++ b/tests/Tool/Command/FileDownloadCommandTest.php @@ -11,10 +11,7 @@ class FileDownloadCommandTest extends TestCase private const URL = 'https://example.com/file'; private const FILE = '/usr/local/bin/file.txt'; - /** - * @var FileDownloadCommand - */ - private $command; + private FileDownloadCommand $command; protected function setUp(): void { diff --git a/tests/Tool/Command/PharDownloadCommandTest.php b/tests/Tool/Command/PharDownloadCommandTest.php index f7c0451c..ca4cd005 100644 --- a/tests/Tool/Command/PharDownloadCommandTest.php +++ b/tests/Tool/Command/PharDownloadCommandTest.php @@ -11,7 +11,7 @@ class PharDownloadCommandTest extends TestCase private const PHAR = 'https://example.com/foo.phar'; private const BIN = '/usr/local/bin/foo'; - private $command; + private PharDownloadCommand $command; protected function setUp(): void { diff --git a/tests/Tool/Command/PhiveInstallCommandTest.php b/tests/Tool/Command/PhiveInstallCommandTest.php index 79431528..7683f104 100644 --- a/tests/Tool/Command/PhiveInstallCommandTest.php +++ b/tests/Tool/Command/PhiveInstallCommandTest.php @@ -12,7 +12,7 @@ class PhiveInstallCommandTest extends TestCase private const BIN = '/usr/local/bin/foo'; private const SIG = '0000000000000000'; - private $command; + private PhiveInstallCommand $command; protected function setUp(): void { diff --git a/tests/UseCase/InstallToolsTest.php b/tests/UseCase/InstallToolsTest.php index 2cad1d2a..5fe8c580 100644 --- a/tests/UseCase/InstallToolsTest.php +++ b/tests/UseCase/InstallToolsTest.php @@ -23,15 +23,9 @@ class InstallToolsTest extends TestCase { - /** - * @var InstallTools - */ - private $useCase; - - /** - * @var Tools|Stub - */ - private $tools; + private InstallTools $useCase; + + private Tools|Stub $tools; protected function setUp(): void {