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

SignatureConfigurator::canConfigure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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