BaseProvider::getModuleName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

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