Passed
Push — master ( 743cc2...6ffec3 )
by Oleg
02:50
created

AbstractAction::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Controllers;
5
6
use SlayerBirden\DFCodeGeneration\Generator\GeneratorInterface;
7
use Twig\Environment;
8
use Twig\Loader\FilesystemLoader;
9
10
abstract class AbstractAction implements GeneratorInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $template = '';
16
    /**
17
     * @var DataProviderInterface
18
     */
19
    protected $provider;
20
21 5
    public function __construct(DataProviderInterface $provider)
22
    {
23 5
        $this->provider = $provider;
24 5
    }
25
26
    /**
27
     * @return string
28
     * @throws \Twig_Error_Loader
29
     * @throws \Twig_Error_Runtime
30
     * @throws \Twig_Error_Syntax
31
     */
32 5
    public function generate(): string
33
    {
34 5
        $loader = new FilesystemLoader(__DIR__ . '/Templates');
35 5
        $twig = new Environment($loader);
36
37 5
        return $twig->load($this->template)->render($this->provider->provide());
38
    }
39
}
40