Completed
Push — feature/issue-165 ( 83f642...d66719 )
by Mikaël
23:02 queued 18s
created

ClassMap::addStructToClassMapList()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 3
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 66
    protected function fillClassMethods()
49
    {
50 66
        $method = new PhpMethod(self::METHOD_NAME, [], PhpMethod::ACCESS_PUBLIC, false, true, true);
51 66
        $this->addMethodBody($method);
52 66
        $this->methods->add($method);
53 66
    }
54
    /**
55
     * @param PhpMethod $method
56
     * @return PhpAnnotationBlock|null
57
     */
58 66
    protected function getMethodAnnotationBlock(PhpMethod $method)
59
    {
60 66
        return new PhpAnnotationBlock([
61 66
            'Returns the mapping between the WSDL Structs and generated Structs\' classes',
62 66
            'This array is sent to the \SoapClient when calling the WS',
63 66
            new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'),
64 33
        ]);
65
    }
66
    /**
67
     * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassAnnotationBlock()
68
     * @return PhpAnnotationBlock
69
     */
70 66
    protected function getClassAnnotationBlock()
71
    {
72 66
        return new PhpAnnotationBlock([
73 66
            'Class which returns the class map definition',
74 66
            new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix()),
75 33
        ]);
76
    }
77
    /**
78
     * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::defineStringMethod()
79
     */
80 66
    protected function defineStringMethod(PhpClass $class)
81
    {
82 66
        return $this;
83
    }
84
    /**
85
     * @param PhpMethod $method
86
     * @return ClassMap
87
     */
88 66
    protected function addMethodBody(PhpMethod $method)
89
    {
90 66
        if ($this->getGenerator()->getStructs()->count() > 0) {
91 66
            $method->addChild('return array(');
92 66
            foreach ($this->getGenerator()->getStructs() as $struct) {
93 66
                $this->addStructToClassMapList($method, $struct);
94 33
            }
95 66
            $method->addChild(');');
96 33
        }
97 66
        return $this;
98
    }
99
    /**
100
     * @param PhpMethod $method
101
     * @param StructModel $struct
102
     * @return ClassMap
103
     */
104 66
    protected function addStructToClassMapList(PhpMethod $method, StructModel $struct)
105
    {
106 66
        if ($struct->isStruct() && !$struct->isRestriction()) {
107 66
            $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 33
        }
109 66
        return $this;
110
    }
111
    /**
112
     * work around for https://bugs.php.net/bug.php?id=69280
113
     * @param StructModel $struct
114
     * @return ClassMap
115
     */
116 66
    protected function getStructName(StructModel $struct)
117
    {
118 66
        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