Completed
Push — master ( 7fbbb0...53f538 )
by Oleg
03:37
created

BaseProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 32
rs 10
c 0
b 0
f 0
ccs 12
cts 13
cp 0.9231
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A provide() 0 7 1
A getModuleName() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\DataProvider;
5
6
use SlayerBirden\DFCodeGeneration\Util\Lexer;
7
8
final class BaseProvider implements DataProviderInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $entityClassName;
14
15 6
    public function __construct(string $entityClassName)
16
    {
17 6
        $this->entityClassName = $entityClassName;
18 6
    }
19
20
    /**
21
     * @return array
22
     */
23 6
    public function provide(): array
24
    {
25
        return [
26 6
            'entityName' => $this->entityClassName,
27 6
            'refName' => Lexer::getRefName($this->entityClassName),
28 6
            'entityClassName' => Lexer::getBaseName($this->entityClassName),
29 6
            'moduleName' => $this->getModuleName($this->entityClassName),
30
        ];
31
    }
32
33 6
    private function getModuleName(string $entityName): string
34
    {
35 6
        $parts = explode('\\', trim($entityName, '\\'));
36 6
        if (isset($parts[2])) {
37 6
            return $parts[2];
38
        }
39
        return end($parts);
40
    }
41
}
42