Skip to content

Commit 5593061

Browse files
committed
Code: add types
1 parent e4b13bc commit 5593061

5 files changed

Lines changed: 19 additions & 35 deletions

File tree

src/CommandLoader/ContainerCommandLoader.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
class ContainerCommandLoader implements CommandLoaderInterface
1111
{
1212

13-
/** @var Container */
14-
private $container;
13+
private Container $container;
1514

1615
/** @var string[] */
17-
private $commandMap;
16+
private array $commandMap;
1817

1918
/**
2019
* @param string[] $commandMap
@@ -28,11 +27,10 @@ public function __construct(Container $container, array $commandMap)
2827
/**
2928
* Loads a command.
3029
*
31-
* @param string $name
3230
* @throws CommandNotFoundException
3331
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
3432
*/
35-
public function get($name): Command
33+
public function get(string $name): Command
3634
{
3735
if (!$this->has($name)) {
3836
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
@@ -44,10 +42,9 @@ public function get($name): Command
4442
/**
4543
* Checks if a command exists.
4644
*
47-
* @param string $name
4845
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
4946
*/
50-
public function has($name): bool
47+
public function has(string $name): bool
5148
{
5249
return array_key_exists($name, $this->commandMap);
5350
}

src/DI/ConsoleExtension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class ConsoleExtension extends CompilerExtension
3030

3131
public const COMMAND_TAG = 'console.command';
3232

33-
/** @var bool */
34-
private $cliMode;
33+
private bool $cliMode;
3534

3635
public function __construct(bool $cliMode = false)
3736
{
@@ -177,7 +176,7 @@ public function beforeCompile(): void
177176
}
178177
} else {
179178
// Parse it from static property
180-
$entry['name'] = call_user_func([$service->getType(), 'getDefaultName']);
179+
$entry['name'] = call_user_func([$service->getType(), 'getDefaultName']); // @phpstan-ignore-line
181180
}
182181

183182
// Validate command name

tests/fixtures/FooCommand.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22

33
namespace Tests\Fixtures;
44

5+
use Symfony\Component\Console\Attribute\AsCommand;
56
use Symfony\Component\Console\Command\Command;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
89

10+
#[AsCommand(
11+
name: 'app:foo',
12+
description: 'Foo command',
13+
)]
914
final class FooCommand extends Command
1015
{
1116

12-
/** @var string */
13-
protected static $defaultName = 'app:foo';
14-
15-
/**
16-
* Configure command
17-
*/
18-
protected function configure(): void
19-
{
20-
$this->setName('foo');
21-
}
22-
2317
protected function execute(InputInterface $input, OutputInterface $output): int
2418
{
2519
return 0;

tests/fixtures/HelperSetCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
namespace Tests\Fixtures;
44

5+
use Symfony\Component\Console\Attribute\AsCommand;
56
use Symfony\Component\Console\Command\Command;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
89

10+
#[AsCommand(
11+
name: 'helper-set'
12+
)]
913
final class HelperSetCommand extends Command
1014
{
1115

12-
/**
13-
* Configure command
14-
*/
1516
protected function configure(): void
1617
{
1718
$this->setName('helper-set');

tests/fixtures/ThrowingCommand.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@
33
namespace Tests\Fixtures;
44

55
use Exception;
6+
use Symfony\Component\Console\Attribute\AsCommand;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910

11+
#[AsCommand(
12+
name: 'throwing'
13+
)]
1014
final class ThrowingCommand extends Command
1115
{
1216

13-
/** @var string */
14-
protected static $defaultName = 'throwing';
15-
1617
public const ERROR_MESSAGE = 'I am internally broken.';
1718

18-
/**
19-
* Configure command
20-
*/
21-
protected function configure(): void
22-
{
23-
$this->setName(self::$defaultName);
24-
}
25-
2619
protected function execute(InputInterface $input, OutputInterface $output): int
2720
{
2821
throw new Exception(self::ERROR_MESSAGE);

0 commit comments

Comments
 (0)