Passed
Push — master ( 4826f7...743cc2 )
by Oleg
04:24
created

Routes::updateExistingFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 6
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Factory;
5
6
use SlayerBirden\DFCodeGeneration\Generator\GeneratorInterface;
7
use Twig\Environment;
8
use Twig\Loader\FilesystemLoader;
9
10
class Routes implements GeneratorInterface
11
{
12
    /**
13
     * @var DataProviderInterface
14
     */
15
    private $provider;
16
17 2
    public function __construct(DataProviderInterface $provider)
18
    {
19 2
        $this->provider = $provider;
20 2
    }
21
22
    /**
23
     * @return string
24
     * @throws \Twig_Error_Loader
25
     * @throws \Twig_Error_Runtime
26
     * @throws \Twig_Error_Syntax
27
     */
28 1
    public function generate(): string
29
    {
30 1
        $loader = new FilesystemLoader(__DIR__);
31 1
        $twig = new Environment($loader);
32
33 1
        return $twig->load('RoutesDelegator.php.twig')->render($this->getParams());
34
    }
35
36 1
    private function getParams(): array
37
    {
38
        return [
39 1
            'ns' => $this->provider->getRoutesDelegatorNameSpace(),
40 1
            'controllerNs' => $this->provider->getControllerNameSpace(),
41 1
            'entityName' => $this->provider->getShortName(),
42
        ];
43
    }
44
45 2
    public function getClassName(): string
46
    {
47 2
        return $this->provider->getRoutesDelegatorNameSpace() . '\\' . $this->provider->getShortName() . 'RoutesDelegator';
48
    }
49
}
50