这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions bin/devkit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -241,10 +238,6 @@ private function toolToHtml(): \Closure
};
}

/**
* @param Collection|string[] $toolsHtml
* @return string
*/
private function renderPage(Collection $toolsHtml): string
{
$template = <<<'TEMPLATE'
Expand Down
5 changes: 4 additions & 1 deletion src/Cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class Application extends CliApplication
{
private $serviceContainer;
private ServiceContainer $serviceContainer;

public function __construct(string $version, ServiceContainer $serviceContainer)
{
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ListCommand extends Command

public const NAME = 'list-tools';

private $listTools;
private ListTools $listTools;

public function __construct(ListTools $listTools)
{
Expand All @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/Cli/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Runner/DryRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class DryRunner implements Runner
{
private $output;
private OutputInterface $output;

public function __construct(OutputInterface $output)
{
Expand Down
28 changes: 26 additions & 2 deletions src/Cli/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class ServiceContainer implements ContainerInterface
{
private $services = [
private array $services = [
InstallCommand::class => 'createInstallCommand',
ListCommand::class => 'createListCommand',
TestCommand::class => 'createTestCommand',
Expand All @@ -33,7 +33,7 @@ class ServiceContainer implements ContainerInterface
Tools::class => 'createTools',
];

private $runtimeServices = [
private array $runtimeServices = [
InputInterface::class => null,
OutputInterface::class => null,
];
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
14 changes: 12 additions & 2 deletions src/Cli/ServiceContainer/LazyRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 17 additions & 3 deletions src/Cli/ServiceContainer/RunnerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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));
Expand All @@ -43,6 +49,10 @@ private function createRealRunner()
return new PassthruRunner();
}

/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function parameters(): array
{
if ($targetDir = $this->targetDir()) {
Expand All @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Json/Factory/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/Json/JsonTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +22,8 @@ public function __construct(callable $resourceLocator)
}

/**
* @return Collection|Tool[]
* @param Filter $filter
* @return Collection
*/
public function all(Filter $filter): Collection
{
Expand Down
8 changes: 4 additions & 4 deletions src/Runner/ParametrisedRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Tool/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class Collection implements IteratorAggregate, Countable
{
/**
* @var array
*/
private $elements;
private array $elements;

private function __construct(array $elements)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Tool/Command/BoxBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading