BaseProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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