RequestMessageBuilder::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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 17
 */
10
namespace FlexPHP\Generator\Domain\Builders\Controller;
11 17
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Schema\Constants\Action;
14 17
use FlexPHP\Schema\SchemaAttributeInterface;
15
use FlexPHP\Schema\SchemaInterface;
16 17
17
final class RequestMessageBuilder extends AbstractBuilder
18
{
19 17
    public function __construct(SchemaInterface $schema, string $action)
20
    {
21 17
        $entity = $this->getInflector()->entity($schema->name());
22
        $item = $this->getInflector()->item($schema->name());
23
        $action = $this->getInflector()->pascalAction($action);
24
        $createdBy = '';
25
        $updatedBy = '';
26
        $hasFilter = $schema->hasAction(Action::FILTER);
27
28
        \array_filter(
29
            $schema->attributes(),
30
            // @phpstan-ignore-next-line
31
            function (SchemaAttributeInterface $property) use (&$createdBy, &$updatedBy): void {
32
                if ($property->isCb()) {
33
                    $createdBy = $this->getInflector()->camelProperty((string)$property->fkId());
34
                }
35
36
                if ($property->isUb()) {
37
                    $updatedBy = $this->getInflector()->camelProperty((string)$property->fkId());
38
                }
39
            }
40
        );
41
42
        parent::__construct(\compact('entity', 'item', 'action', 'createdBy', 'updatedBy', 'hasFilter'));
43
    }
44
45
    public function build(): string
46
    {
47
        return \rtrim(parent::build());
48
    }
49
50
    protected function getFileTemplate(): string
51
    {
52
        return 'RequestMessage.php.twig';
53
    }
54
55
    protected function getPathTemplate(): string
56
    {
57
        return \sprintf('%1$s/Symfony/src/Controller', parent::getPathTemplate());
58
    }
59
}
60