BaseProvider   A
last analyzed

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 20
    public function __construct(string $entityClassName)
16
    {
17 20
        $this->entityClassName = $entityClassName;
18 20
    }
19
20
    /**
21
     * @return array
22
     */
23 20
    public function provide(): array
24
    {
25
        return [
26 20
            'entityName' => $this->entityClassName,
27 20
            'refName' => Lexer::getRefName($this->entityClassName),
28 20
            'entityClassName' => Lexer::getBaseName($this->entityClassName),
29 20
            'moduleName' => $this->getModuleName($this->entityClassName),
30
        ];
31
    }
32
33 20
    private function getModuleName(string $entityName): string
34
    {
35 20
        $parts = explode('\\', trim($entityName, '\\'));
36 20
        if (isset($parts[2])) {
37 20
            return $parts[2];
38
        }
39
        return end($parts);
40
    }
41
}
42