Completed
Push — master ( f81cf6...7fbbb0 )
by Oleg
03:40
created

SpecCodeFeederPart   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 25
rs 10
c 0
b 0
f 0
ccs 13
cts 13
cp 1
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCalleeCode() 0 3 1
A feed() 0 7 1
A matches() 0 3 1
A getMethodName() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Config\Code\Parts;
5
6
use Nette\PhpGenerator\ClassType;
7
use Nette\PhpGenerator\PhpLiteral;
8
use Nette\PhpGenerator\PhpNamespace;
9
use SlayerBirden\DFCodeGeneration\Code\Printer\NsArrayPrinter;
10
use SlayerBirden\DFCodeGeneration\Generator\Config\Code\ArrayPartInterface;
11
use Zend\Filter\Word\UnderscoreToCamelCase;
12
13
final class SpecCodeFeederPart implements ArrayPartInterface
14
{
15 2
    public function feed(string $key, array $data, ClassType $class, PhpNamespace $namespace): void
16
    {
17 2
        $class->addMethod($this->getMethodName($key))
18 2
            ->setVisibility(ClassType::VISIBILITY_PUBLIC)
19 2
            ->setReturnType('array')
20 2
            ->setBody(
21 2
                sprintf('return %s;', (new NsArrayPrinter($namespace))->printArray($data, 1, ''))
22
            );
23 2
    }
24
25 2
    private function getMethodName(string $key): string
26
    {
27 2
        return 'get' . str_replace('\\', '', $key) . 'Spec';
28
    }
29
30 2
    public function matches(string $key): bool
31
    {
32 2
        return true;
33
    }
34
35 2
    public function getCalleeCode(string $key, array $data, PhpNamespace $namespace): PhpLiteral
36
    {
37 2
        return new PhpLiteral(sprintf('$this->%s()', $this->getMethodName($key)));
38
    }
39
}
40