Passed
Push — develop ( bcbf5d...e03cb7 )
by Mikaël
08:55
created

ClassMap::fillClassConstants()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PackageGenerator\File;
6
7
use WsdlToPhp\PackageGenerator\Container\PhpElement\Constant as ConstantContainer;
8
use WsdlToPhp\PackageGenerator\Container\PhpElement\Property as PropertyContainer;
9
use WsdlToPhp\PackageGenerator\Model\Struct as StructModel;
10
use WsdlToPhp\PhpGenerator\Element\PhpAnnotation;
11
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock;
12
use WsdlToPhp\PhpGenerator\Element\PhpConstant;
13
use WsdlToPhp\PhpGenerator\Element\PhpMethod;
14
use WsdlToPhp\PhpGenerator\Element\PhpProperty;
15
16
final class ClassMap extends AbstractModelFile
17
{
18
    public const METHOD_NAME = 'get';
19
20 22
    protected function fillClassConstants(ConstantContainer $constants): void
21
    {
22 22
    }
23
24
    protected function getConstantAnnotationBlock(PhpConstant $constant): ?PhpAnnotationBlock
25
    {
26
    }
27
28 22
    protected function fillClassProperties(PropertyContainer $properties): void
29
    {
30 22
    }
31
32
    protected function getPropertyAnnotationBlock(PhpProperty $property): ?PhpAnnotationBlock
33
    {
34
    }
35
36 22
    protected function fillClassMethods(): void
37
    {
38 22
        $method = new PhpMethod(self::METHOD_NAME, [], self::TYPE_ARRAY, PhpMethod::ACCESS_PUBLIC, false, true, true);
39 22
        $this->addMethodBody($method);
40 22
        $this->methods->add($method);
41 22
    }
42
43 22
    protected function getMethodAnnotationBlock(PhpMethod $method): ?PhpAnnotationBlock
44
    {
45 22
        return new PhpAnnotationBlock([
46 22
            'Returns the mapping between the WSDL Structs and generated Structs\' classes',
47 22
            'This array is sent to the \SoapClient when calling the WS',
48 22
            new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'),
49
        ]);
50
    }
51
52 22
    protected function getClassAnnotationBlock(): PhpAnnotationBlock
53
    {
54 11
        $annotations = [
55 11
            'Class which returns the class map definition',
56
        ];
57
58 22
        if (!empty($this->getGenerator()->getOptionPrefix())) {
59 6
            $annotations[] = new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix());
60
        }
61
62 22
        return new PhpAnnotationBlock($annotations);
63
    }
64
65 22
    protected function addMethodBody(PhpMethod $method): self
66
    {
67 22
        if ($this->getGenerator()->getStructs()->count() > 0) {
68 22
            $method->addChild('return [');
69 22
            foreach ($this->getGenerator()->getStructs() as $struct) {
70 22
                $this->addStructToClassMapList($method, $struct);
71
            }
72 22
            $method->addChild('];');
73
        }
74
75 22
        return $this;
76
    }
77
78 22
    protected function addStructToClassMapList(PhpMethod $method, StructModel $struct): self
79
    {
80 22
        if ($struct->isStruct() && !$struct->isRestriction()) {
81 22
            $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1));
82
        }
83
84 22
        return $this;
85
    }
86
87
    /**
88
     * Work around for https://bugs.php.net/bug.php?id=69280.
89
     */
90 22
    protected function getStructName(StructModel $struct): string
91
    {
92 22
        return str_replace('\\', '\\\\', $struct->getPackagedName(true));
93
    }
94
}
95