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

StandardProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
dl 0
loc 92
rs 10
c 0
b 0
f 0
ccs 28
cts 30
cp 0.9333
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntitiesSrc() 0 9 2
A getRouteFactoryName() 0 4 1
A getControllerName() 0 9 2
A getConfigNameSpace() 0 6 1
A __construct() 0 3 1
A getInputFilterSpec() 0 3 1
A getCurrentConfig() 0 9 2
A getInputFilterName() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Config;
5
6
use SlayerBirden\DFCodeGeneration\Generator\Factory\NamingTrait as FactoryNamingTrait;
7
use SlayerBirden\DFCodeGeneration\Generator\Controllers\NamingTrait as ControllerNamingTrait;
8
9
class StandardProvider implements DataProviderInterface
10
{
11
    use FactoryNamingTrait, ControllerNamingTrait {
12
        FactoryNamingTrait::getBaseName insteadof ControllerNamingTrait;
13
        FactoryNamingTrait::getNs insteadof ControllerNamingTrait;
14
        FactoryNamingTrait::getNs as getFactoryNs;
15
        ControllerNamingTrait::getNs as getControllerNs;
16
    }
17
18
    /**
19
     * @var string
20
     */
21
    private $entityClassName;
22
23 11
    public function __construct(string $entityClassName)
24
    {
25 11
        $this->entityClassName = $entityClassName;
26 11
    }
27
28
    /**
29
     * @return string
30
     * @throws \ReflectionException
31
     */
32 1
    public function getRouteFactoryName(): string
33
    {
34 1
        $baseName = $this->getBaseName($this->entityClassName);
35 1
        return $this->getFactoryNs($this->entityClassName) . "\\{$baseName}RoutesDelegator";
36
    }
37
38
    /**
39
     * @return array
40
     * @throws \Doctrine\Common\Annotations\AnnotationException
41
     * @throws \ReflectionException
42
     */
43 1
    public function getInputFilterSpec(): array
44
    {
45 1
        return (new ReflectionInputFilter($this->entityClassName))->getSpec();
46
    }
47
48 1
    public function getEntitiesSrc(): string
49
    {
50
        // expect to have 3d part as Module
51 1
        $parts = explode('\\', $this->entityClassName);
52 1
        if (isset($parts[2])) {
53 1
            return sprintf('src/%s/Entities', $parts[2]);
54
        }
55
56
        return '';
57
    }
58
59 1
    public function getCurrentConfig(): array
60
    {
61 1
        $config = $this->getConfigNameSpace() . '\\' . 'ConfigProvider';
62
63 1
        if (class_exists($config)) {
64
            return (new $config())();
65
        }
66
67 1
        return [];
68
    }
69
70
    /**
71
     * @param string $type
72
     * @return string
73
     * @throws \ReflectionException
74
     */
75 5
    public function getControllerName(string $type): string
76
    {
77 5
        $baseName = $this->getBaseName($this->entityClassName);
78 5
        if ($type === 'gets') {
79 1
            $baseName .= 's';
80 1
            $type = 'get';
81
        }
82
83 5
        return $this->getControllerNs($this->entityClassName) . '\\' . ucwords($type) . $baseName . 'Action';
84
    }
85
86 2
    public function getConfigNameSpace(): string
87
    {
88 2
        $parts = explode('\\', $this->entityClassName);
89 2
        array_splice($parts, -2); // Entities\Model
90
91 2
        return ltrim(implode('\\', $parts), '\\');
92
    }
93
94
    /**
95
     * @return string
96
     * @throws \ReflectionException
97
     */
98 1
    public function getInputFilterName(): string
99
    {
100 1
        return $this->getBaseName($this->entityClassName) . 'InputFilter';
101
    }
102
}
103