Completed
Push — master ( 6ffec3...6f905d )
by Oleg
06:32
created

SimpleProvider::getNs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Controllers;
5
6
use SlayerBirden\DFCodeGeneration\Generator\BaseNameTrait;
7
8
class SimpleProvider implements DataProviderInterface
9
{
10
    use BaseNameTrait;
11
12
    /**
13
     * @var string
14
     */
15
    protected $entityClassName;
16
17 13
    public function __construct(string $entityClassName)
18
    {
19 13
        $this->entityClassName = $entityClassName;
20 13
    }
21
22
    /**
23
     * @return array
24
     * @throws \ReflectionException
25
     */
26 8
    public function provide(): array
27
    {
28
        return [
29 8
            'ns' => $this->getNs(),
30 8
            'useStatement' => ltrim($this->entityClassName, '\\'),
31 8
            'entityName' => $this->getBaseName(),
32
        ];
33
    }
34
35
    /**
36
     * @param string $type
37
     * @return string
38
     * @throws \ReflectionException
39
     */
40 5
    public function getClassName(string $type): string
41
    {
42 5
        if ($type === 'gets') {
43 1
            $className = 'Get' . $this->getBaseName() . 'sAction';
44
        } else {
45 4
            $className = ucwords($type) . $this->getBaseName() . 'Action';
46
        }
47
48 5
        return $this->getNs() . "\\$className";
49
    }
50
51 13
    private function getNs(): string
52
    {
53 13
        $parts = explode('\\', $this->entityClassName);
54 13
        array_splice($parts, -2); // Entities\Model
55
56 13
        $parts[] = 'Controller';
57
58 13
        return ltrim(implode('\\', $parts), '\\');
59
    }
60
}
61