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

AttributeConfigurator::configure()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 3
nc 4
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\Attribute\Parser;
9
10
/**
11
 * @internal
12
 */
13
final class AttributeConfigurator 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 $this->parser->hasCommandAttribute($reflection);
23
    }
24
25
    public function configure(Command $command, \ReflectionClass $reflection): void
26
    {
27
        $result = $this->parser->parse($reflection);
28
29
        $command->setName($result->name);
30
        $command->setDescription((string) $result->description);
31
        $command->setHelp((string) $result->help);
32
33
        foreach ($result->options as $option) {
34
            $command->getDefinition()->addOption($option);
35
        }
36
37
        foreach ($result->arguments as $argument) {
38
            $command->getDefinition()->addArgument($argument);
39
        }
40
    }
41
}
42