CommandBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
ccs 1
cts 1
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPathTemplate() 0 3 1
A getFileTemplate() 0 3 1
A __construct() 0 12 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9 1
 */
10
namespace FlexPHP\Generator\Domain\Builders\Command;
11 1
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Schema\SchemaAttributeInterface;
14 1
use FlexPHP\Schema\SchemaInterface;
15
16 1
final class CommandBuilder extends AbstractBuilder
17
{
18
    public function __construct(SchemaInterface $schema, string $action)
19
    {
20
        $entity = $this->getInflector()->entity($schema->name());
21
        $action = $this->getInflector()->pascalAction($action);
22
        $command = $this->getInflector()->commandName($entity, $action);
23
        $properties = \array_reduce($schema->attributes(), function ($result, SchemaAttributeInterface $property) {
24
            $result[$property->name()] = $property;
25
26
            return $result;
27
        }, []);
28
29
        parent::__construct(\compact('entity', 'action', 'properties', 'command'));
30
    }
31
32
    protected function getFileTemplate(): string
33
    {
34
        return 'Command.php.twig';
35
    }
36
37
    protected function getPathTemplate(): string
38
    {
39
        return \sprintf('%1$s/FlexPHP/Command', parent::getPathTemplate());
40
    }
41
}
42