ControllerBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 27
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileTemplate() 0 3 1
A getPathTemplate() 0 3 1
A __construct() 0 15 2
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 6
 */
10
namespace FlexPHP\Generator\Domain\Builders\Controller;
11 6
12 6
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
13 6
use FlexPHP\Schema\Constants\Action;
14 6
use FlexPHP\Schema\SchemaInterface;
15
16
final class ControllerBuilder extends AbstractBuilder
17
{
18 6
    public function __construct(SchemaInterface $schema, array $actions)
19 6
    {
20
        $entity = $this->getInflector()->entity($schema->name());
21 6
        $route = $this->getInflector()->route($schema->name());
22
        $fkFns = $this->getFkFunctions($schema->fkRelations());
23 6
        $header = self::getHeaderFile();
24
        $hasFilter = $schema->hasAction(Action::FILTER);
25
        unset($actions['login']);
26 6
27
        foreach ($actions as $action => $builder) {
28 6
            $actions[$this->getInflector()->pascalAction($action)] = $builder;
29
            unset($actions[$action]);
30
        }
31
32
        parent::__construct(\compact('entity', 'actions', 'route', 'fkFns', 'header', 'hasFilter'));
33
    }
34
35
    protected function getFileTemplate(): string
36
    {
37
        return 'Controller.php.twig';
38
    }
39
40
    protected function getPathTemplate(): string
41
    {
42
        return \sprintf('%1$s/Symfony/src/Controller', parent::getPathTemplate());
43
    }
44
}
45