Completed
Push — develop ( b8005e...fd13fe )
by Freddie
03:18
created

EntityBuilder   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 51
ccs 26
cts 26
cp 1
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileTemplate() 0 3 1
A __construct() 0 13 3
A getPathTemplate() 0 3 1
A getSetters() 0 11 2
A getGetters() 0 11 2
1
<?php
2
3
namespace FlexPHP\Generator\Domain\Builders\Entity;
4
5
use FlexPHP\Generator\Domain\Builders\AbstractBuilder;
6
7
class EntityBuilder extends AbstractBuilder
8
{
9 3
    public function __construct(array $data, array $config = [])
10
    {
11 3
        $name = $data['name'];
12 3
        $properties = !empty($data['properties']) && \is_array($data['properties'])
13 3
            ? $data['properties']
14 3
            : [];
15
16 3
        $_properties = \array_keys($properties);
17
18 3
        $getters = $this->getGetters($properties);
19 3
        $setters = $this->getSetters($properties);
20
21 3
        parent::__construct(\compact('name', '_properties', 'getters', 'setters'), $config);
22 3
    }
23
24 3
    public function getFileTemplate(): string
25
    {
26 3
        return 'Entity.php.twig';
27
    }
28
29 3
    public function getPathTemplate(): string
30
    {
31 3
        return \sprintf('%1$s/FlexPHP/Entity', parent::getPathTemplate());
32
    }
33
34 3
    private function getGetters(array $properties): array
35
    {
36 3
        $getters = [];
37
38 3
        foreach ($properties as $name => $attributes) {
39 3
            $getters[$name] = new GetterBuilder([
40 3
                $name => $attributes
41
            ]);
42
        }
43
44 3
        return $getters;
45
    }
46
47 3
    private function getSetters(array $properties): array
48
    {
49 3
        $setters = [];
50
51 3
        foreach ($properties as $name => $attributes) {
52 3
            $setters[$name] = new SetterBuilder([
53 3
                $name => $attributes
54
            ]);
55
        }
56
57 3
        return $setters;
58
    }
59
}
60