Passed
Push — master ( 743cc2...6ffec3 )
by Oleg
02:50
created

SimpleProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 0
cts 2
cp 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Controllers;
5
6
class SimpleProvider implements DataProviderInterface
7
{
8
    use NamingTrait;
9
10
    /**
11
     * @var string
12
     */
13
    protected $entityClassName;
14
15
    public function __construct(string $entityClassName)
16
    {
17
        $this->entityClassName = $entityClassName;
18
    }
19
20
    /**
21
     * @return array
22
     * @throws \ReflectionException
23
     */
24
    public function provide(): array
25
    {
26
        return [
27
            'ns' => $this->getNs($this->entityClassName),
28
            'useStatement' => ltrim($this->entityClassName, '\\'),
29
            'entityName' => $this->getBaseName($this->entityClassName),
30
        ];
31
    }
32
33
    /**
34
     * @param string $type
35
     * @return string
36
     * @throws \ReflectionException
37
     */
38
    public function getClassName(string $type): string
39
    {
40
        if ($type === 'gets') {
41
            $className = 'Get' . $this->getBaseName($this->entityClassName) . 'sAction';
42
        } else {
43
            $className = ucwords($type) . $this->getBaseName($this->entityClassName) . 'Action';
44
        }
45
46
        return $this->getNs($this->entityClassName) . "\\$className";
47
    }
48
}
49