Passed
Push — 2.x ( bef6c0...34f135 )
by Mikaël
03:54
created

ClassMap::getClassAnnotationBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File;
4
5
use WsdlToPhp\PackageGenerator\Model\Struct as StructModel;
6
use WsdlToPhp\PhpGenerator\Element\PhpMethod;
7
use WsdlToPhp\PhpGenerator\Component\PhpClass;
8
use WsdlToPhp\PhpGenerator\Element\PhpConstant;
9
use WsdlToPhp\PhpGenerator\Element\PhpAnnotation;
10
use WsdlToPhp\PhpGenerator\Element\PhpProperty;
11
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock;
12
use WsdlToPhp\PackageGenerator\Container\PhpElement\Method as MethodContainer;
13
use WsdlToPhp\PackageGenerator\Container\PhpElement\Property as PropertyContainer;
14
use WsdlToPhp\PackageGenerator\Container\PhpElement\Constant as ConstantContainer;
15
16
class ClassMap extends AbstractModelFile
17
{
18
    /**
19
     * @var string
20
     */
21
    const METHOD_NAME = 'get';
22
    /**
23
     * @param ConstantContainer $constants
24
     */
25 66
    protected function getClassConstants(ConstantContainer $constants)
26
    {
27 66
    }
28
    /**
29
     * @param PhpConstant $constant
30
     * @return PhpAnnotationBlock|null
31
     */
32
    protected function getConstantAnnotationBlock(PhpConstant $constant)
33
    {
34
    }
35
    /**
36
     * @param PropertyContainer $properties
37
     */
38 66
    protected function getClassProperties(PropertyContainer $properties)
39
    {
40 66
    }
41
    /**
42
     * @param PhpProperty $property
43
     * @return PhpAnnotationBlock|null
44
     */
45
    protected function getPropertyAnnotationBlock(PhpProperty $property)
46
    {
47
    }
48
    protected function fillClassMethods()
49
    {
50
        $method = new PhpMethod(self::METHOD_NAME, [], PhpMethod::ACCESS_PUBLIC, false, true, true);
51
        $this->addMethodBody($method);
52 66
        $this->methods->add($method);
53
    }
54 66
    /**
55 66
     * @param PhpMethod $method
56 66
     * @return PhpAnnotationBlock|null
57 66
     */
58
    protected function getMethodAnnotationBlock(PhpMethod $method)
59
    {
60
        return new PhpAnnotationBlock([
61
            'Returns the mapping between the WSDL Structs and generated Structs\' classes',
62
            'This array is sent to the \SoapClient when calling the WS',
63 66
            new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'),
64
        ]);
65 66
    }
66 66
    /**
67 66
     * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassAnnotationBlock()
68 66
     * @return PhpAnnotationBlock
69 33
     */
70
    protected function getClassAnnotationBlock()
71
    {
72
        return new PhpAnnotationBlock([
73
            'Class which returns the class map definition',
74
            new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix()),
75 66
        ]);
76
    }
77 66
    /**
78 66
     * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::defineStringMethod()
79 66
     */
80 33
    protected function defineStringMethod(PhpClass $class)
81
    {
82
        return $this;
83
    }
84
    /**
85 66
     * @param PhpMethod $method
86
     * @return ClassMap
87 66
     */
88
    protected function addMethodBody(PhpMethod $method)
89
    {
90
        if ($this->getGenerator()->getStructs()->count() > 0) {
91
            $method->addChild('return array(');
92
            foreach ($this->getGenerator()->getStructs() as $struct) {
93 66
                $this->addStructToClassMapList($method, $struct);
94
            }
95 66
            $method->addChild(');');
96 66
        }
97 66
        return $this;
98 66
    }
99 33
    /**
100 66
     * @param PhpMethod $method
101 33
     * @param StructModel $struct
102 66
     * @return ClassMap
103
     */
104
    protected function addStructToClassMapList(PhpMethod $method, StructModel $struct)
105
    {
106
        if ($struct->isStruct() && !$struct->isRestriction()) {
107
            $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1));
0 ignored issues
show
Bug introduced by
$this->getStructName($struct) of type WsdlToPhp\PackageGenerator\File\ClassMap is incompatible with the type string expected by parameter $args of sprintf(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
            $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), /** @scrutinizer ignore-type */ $this->getStructName($struct)), 1));
Loading history...
108
        }
109 66
        return $this;
110
    }
111 66
    /**
112 66
     * work around for https://bugs.php.net/bug.php?id=69280
113 33
     * @param StructModel $struct
114 66
     * @return ClassMap
115
     */
116
    protected function getStructName(StructModel $struct)
117
    {
118
        return str_replace('\\', '\\\\', $struct->getPackagedName(true));
0 ignored issues
show
Bug Best Practice introduced by
The expression return str_replace('\', ...>getPackagedName(true)) returns the type string which is incompatible with the documented return type WsdlToPhp\PackageGenerator\File\ClassMap.
Loading history...
119
    }
120
}
121