Completed
Push — develop ( 3d0c4c...e7cba6 )
by Freddie
13:19 queued 12s
created

TemplateBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
A getFileTemplate() 0 3 1
A getPathTemplate() 0 3 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\Template;
11
12
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13
use FlexPHP\Inputs\Builder\InputBuilder;
0 ignored issues
show
Bug introduced by
The type FlexPHP\Inputs\Builder\InputBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use FlexPHP\Schema\Constants\Keyword;
15
use Jawira\CaseConverter\Convert;
16
17
final class TemplateBuilder extends AbstractBuilder
18
{
19
    private $action;
20
21
    public function __construct(string $entity, string $action, array $properties)
22
    {
23
        $this->action = $action;
24
25
        $name = $this->getPascalCase($this->getSingularize($entity));
26
        $entity = $this->getPascalCase($this->getPluralize($entity));
27
        $route = $this->getDashCase($entity);
28
        $item = $this->getCamelCase($this->getSingularize($entity));
29
        $headers = \array_reduce($properties, function (array $result, array $property) {
30
            $result[] = (new Convert($property[Keyword::NAME]))->toTitle();
31
32
            return $result;
33
        }, []);
34
35
        $properties = \array_reduce($properties, function (array $result, array $property) {
36
            $result[$this->getCamelCase($property[Keyword::NAME])] = $property;
37
38
            return $result;
39
        }, []);
40
41
        parent::__construct(\compact('name', 'entity', 'route', 'item', 'headers', 'properties'));
42
    }
43
44
    protected function getFileTemplate(): string
45
    {
46
        return $this->action . '.html.twig';
47
    }
48
49
    protected function getPathTemplate(): string
50
    {
51
        return \sprintf('%1$s/Symfony/v43/templates', parent::getPathTemplate());
52
    }
53
}
54