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

AbstractBuilder::getSnakeCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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