SpecCodeFeederPart::feed()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 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