Test Failed
Pull Request — master (#872)
by Maxim
12:26 queued 05:23
created

SignatureConfigurator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 3
A canConfigure() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Console\Configurator;
6
7
use Spiral\Console\Command;
8
use Spiral\Console\Configurator\Signature\Parser;
9
10
/**
11
 * @internal
12
 */
13
final class SignatureConfigurator implements ConfiguratorInterface
14
{
15
    public function __construct(
16
        private readonly Parser $parser
17
    ) {
18
    }
19
20
    public function canConfigure(Command $command, \ReflectionClass $reflection): bool
21
    {
22
        return $reflection->getConstant('SIGNATURE') !== null;
23
    }
24
25
    public function configure(Command $command, \ReflectionClass $reflection): void
26
    {
27
        $result = $this->parser->parse((string) $reflection->getConstant('SIGNATURE'));
28
29
        $command->setName($result->name);
30
31
        foreach ($result->options as $option) {
32
            $command->getDefinition()->addOption($option);
33
        }
34
35
        foreach ($result->arguments as $argument) {
36
            $command->getDefinition()->addArgument($argument);
37
        }
38
    }
39
}
40