TranslateBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 26
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileTemplate() 0 3 1
A getPathTemplate() 0 3 1
A __construct() 0 14 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
 */
10
namespace FlexPHP\Generator\Domain\Builders\Translate;
11
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Schema\Constants\Action;
14
use FlexPHP\Schema\SchemaAttributeInterface;
15
use FlexPHP\Schema\SchemaInterface;
16
17
final class TranslateBuilder extends AbstractBuilder
18
{
19
    public function __construct(SchemaInterface $schema)
20
    {
21
        $titleSingular = $this->getInflector()->entityTitleSingular($schema->name());
22
        $titlePlural = $this->getInflector()->entityTitlePlural($schema->name());
23
        $hasFilter = $schema->hasAction(Action::FILTER);
24
        $headers = \array_reduce($schema->attributes(), function (array $result, SchemaAttributeInterface $property) {
25
            $result[
26
                $this->getInflector()->camelProperty($property->name())
27
            ] = $this->getInflector()->propertyTitle($property->name());
28
29
            return $result;
30
        }, []);
31
32
        parent::__construct(\compact('titleSingular', 'titlePlural', 'headers', 'hasFilter'));
33
    }
34
35
    protected function getFileTemplate(): string
36
    {
37
        return 'translate.php.twig';
38
    }
39
40
    protected function getPathTemplate(): string
41
    {
42
        return \sprintf('%1$s/Symfony/templates', parent::getPathTemplate());
43
    }
44
}
45