SpecCodeFeederPart   A
last analyzed

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 4
    public function feed(string $key, array $data, ClassType $class, PhpNamespace $namespace): void
16
    {
17 4
        $class->addMethod($this->getMethodName($key))
18 4
            ->setVisibility(ClassType::VISIBILITY_PRIVATE)
19 4
            ->setReturnType('array')
20 4
            ->setBody(
21 4
                sprintf('return %s;', (new NsArrayPrinter($namespace))->printArray($data, 1, ''))
22
            );
23 4
    }
24
25 4
    private function getMethodName(string $key): string
26
    {
27 4
        return 'get' . str_replace('\\', '', $key) . 'Spec';
28
    }
29
30 4
    public function matches(string $key): bool
31
    {
32 4
        return true;
33
    }
34
35 4
    public function getCalleeCode(string $key, array $data, PhpNamespace $namespace): PhpLiteral
36
    {
37 4
        return new PhpLiteral(sprintf('$this->%s()', $this->getMethodName($key)));
38
    }
39
}
40