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

SimpleProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
ccs 0
cts 12
cp 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getClassName() 0 9 2
A provide() 0 6 1
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