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

BaseProvider::__construct()   A

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 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