TemplateBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 20
rs 9.8666
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
 */
10
namespace FlexPHP\Generator\Domain\Builders\Template;
11
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Schema\SchemaAttributeInterface;
14
use FlexPHP\Schema\SchemaInterface;
15
16
final class TemplateBuilder extends AbstractBuilder
17
{
18
    private string $action;
19
20
    public function __construct(SchemaInterface $schema, string $action)
21
    {
22
        $this->action = $action;
23
24
        $route = $this->getInflector()->route($schema->name());
25
        $item = $this->getInflector()->item($schema->name());
26
        $items = $this->getInflector()->items($schema->name());
27
        $fkRels = $this->getFkRelations($schema->fkRelations());
28
        $pkName = $this->getInflector()->camelProperty($schema->pkName());
29
        $properties = \array_reduce(
30
            $schema->attributes(),
31
            function (array $result, SchemaAttributeInterface $property) {
32
                $result[$this->getInflector()->camelProperty($property->name())] = $property;
33
34
                return $result;
35
            },
36
            []
37
        );
38
39
        parent::__construct(\compact('route', 'item', 'items', 'properties', 'fkRels', 'pkName'));
40
    }
41
42
    protected function getFileTemplate(): string
43
    {
44
        return $this->action . '.html.twig';
45
    }
46
47
    protected function getPathTemplate(): string
48
    {
49
        return \sprintf('%1$s/Symfony/templates', parent::getPathTemplate());
50
    }
51
}
52