Passed
Push — develop ( e6f84d...350782 )
by Mikaël
09:01 queued 28s
created

ClassMap   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 86.21%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 79
ccs 25
cts 29
cp 0.8621
rs 10
c 3
b 0
f 0
wmc 15

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getStructName() 0 3 1
A fillClassConstants() 0 2 1
A fillClassMethods() 0 5 1
A getConstantAnnotationBlock() 0 3 1
A addMethodBody() 0 11 3
A getPropertyAnnotationBlock() 0 3 1
A addStructToClassMapList() 0 7 3
A getClassAnnotationBlock() 0 11 2
A fillClassProperties() 0 2 1
A getMethodAnnotationBlock() 0 6 1
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
    protected function fillClassConstants(ConstantContainer $constants): void
21
    {
22
    }
23
24
    protected function getConstantAnnotationBlock(PhpConstant $constant): ?PhpAnnotationBlock
25
    {
26
        return null;
27
    }
28
29
    protected function fillClassProperties(PropertyContainer $properties): void
30
    {
31
    }
32
33
    protected function getPropertyAnnotationBlock(PhpProperty $property): ?PhpAnnotationBlock
34
    {
35
        return null;
36
    }
37
38 16
    protected function fillClassMethods(): void
39
    {
40 16
        $method = new PhpMethod(self::METHOD_NAME, [], self::TYPE_ARRAY, PhpMethod::ACCESS_PUBLIC, false, true, true);
41 16
        $this->addMethodBody($method);
42 16
        $this->methods->add($method);
43
    }
44
45 16
    protected function getMethodAnnotationBlock(PhpMethod $method): ?PhpAnnotationBlock
46
    {
47 16
        return new PhpAnnotationBlock([
48
            'Returns the mapping between the WSDL Structs and generated Structs\' classes',
49
            'This array is sent to the \SoapClient when calling the WS',
50 16
            new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'),
51
        ]);
52
    }
53
54 16
    protected function getClassAnnotationBlock(): PhpAnnotationBlock
55
    {
56 11
        $annotations = [
57
            'Class which returns the class map definition',
58
        ];
59
60 16
        if (!empty($this->getGenerator()->getOptionPrefix())) {
61 6
            $annotations[] = new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix());
62
        }
63
64 16
        return new PhpAnnotationBlock($annotations);
65
    }
66
67 16
    protected function addMethodBody(PhpMethod $method): self
68
    {
69 16
        if ($this->getGenerator()->getStructs()->count() > 0) {
70 16
            $method->addChild('return [');
71 16
            foreach ($this->getGenerator()->getStructs() as $struct) {
72 16
                $this->addStructToClassMapList($method, $struct);
73
            }
74 16
            $method->addChild('];');
75
        }
76
77 16
        return $this;
78
    }
79
80 16
    protected function addStructToClassMapList(PhpMethod $method, StructModel $struct): self
81
    {
82 16
        if ($struct->isStruct() && !$struct->isRestriction()) {
83 16
            $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1));
84
        }
85
86 16
        return $this;
87
    }
88
89
    /**
90
     * Work around for https://bugs.php.net/bug.php?id=69280.
91
     */
92 16
    protected function getStructName(StructModel $struct): string
93
    {
94 16
        return str_replace('\\', '\\\\', $struct->getPackagedName(true));
95
    }
96
}
97