Test Setup Failed
Push — develop ( 17b215...d74e9d )
by Freddie
13:13
created

AbstractBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 40
ccs 16
cts 16
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPathTemplate() 0 3 1
A __toString() 0 3 1
A __construct() 0 7 3
A build() 0 6 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;
11
12
use FlexPHP\Generator\Domain\Traits\InflectorTrait;
13
14
abstract class AbstractBuilder implements BuilderInterface
15
{
16
    use InflectorTrait;
17
18
    /**
19
     * @var array<array|string>
20
     */
21
    private $data;
22
23 69
    /**
24
     * @param array<array|string> $data
25 69
     */
26 23
    public function __construct(array $data)
27
    {
28
        if (!empty($data['action']) && \is_string($data['action'])) {
29 69
            $data['action_name'] = $this->getPascalCase($data['action']);
30 69
        }
31 69
32
        $this->data = $data;
33 69
    }
34
35 69
    public function __toString()
36
    {
37
        return $this->build();
38 69
    }
39
40 69
    public function build(): string
41 69
    {
42
        $loader = new \Twig\Loader\FilesystemLoader($this->getPathTemplate());
43 69
        $twig = new \Twig\Environment($loader);
44
45
        return $twig->render($this->getFileTemplate(), $this->data);
46 4
    }
47
48 4
    protected function getPathTemplate(): string
49
    {
50
        return \sprintf('%1$s/../BoilerPlates', __DIR__);
51 64
    }
52
53 64
    abstract protected function getFileTemplate(): string;
54
}
55