Passed
Push — feature/issue-165 ( 2b7e50...101bca )
by Mikaël
14:10
created

ClassMap::getClassProperties()   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
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
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
    /**
49
     * @return ClassMap
50
     */
51
    protected function fillClassMethods()
52 66
    {
53
        $method = new PhpMethod(self::METHOD_NAME, [], PhpMethod::ACCESS_PUBLIC, false, true, true);
54 66
        $this->addMethodBody($method);
55 66
        $this->methods->add($method);
56 66
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type WsdlToPhp\PackageGenerator\File\ClassMap which is incompatible with the return type mandated by WsdlToPhp\PackageGenerat...ile::fillClassMethods() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
57 66
    }
58
    /**
59
     * @param PhpMethod $method
60
     * @return PhpAnnotationBlock|null
61
     */
62
    protected function getMethodAnnotationBlock(PhpMethod $method)
63 66
    {
64
        return new PhpAnnotationBlock([
65 66
            'Returns the mapping between the WSDL Structs and generated Structs\' classes',
66 66
            'This array is sent to the \SoapClient when calling the WS',
67 66
            new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'),
68 66
        ]);
69 33
    }
70
    /**
71
     * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassAnnotationBlock()
72
     * @return PhpAnnotationBlock
73
     */
74
    protected function getClassAnnotationBlock()
75 66
    {
76
        return new PhpAnnotationBlock([
77 66
            'Class which returns the class map definition',
78 66
            new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix()),
79 66
        ]);
80 33
    }
81
    /**
82
     * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::defineStringMethod()
83
     */
84
    protected function defineStringMethod(PhpClass $class)
85 66
    {
86
        return $this;
87 66
    }
88
    /**
89
     * @param PhpMethod $method
90
     * @return ClassMap
91
     */
92
    protected function addMethodBody(PhpMethod $method)
93 66
    {
94
        if ($this->getGenerator()->getStructs()->count() > 0) {
95 66
            $method->addChild('return array(');
96 66
            foreach ($this->getGenerator()->getStructs() as $struct) {
97 66
                $this->addStructToClassMapList($method, $struct);
98 66
            }
99 33
            $method->addChild(');');
100 66
        }
101 33
        return $this;
102 66
    }
103
    /**
104
     * @param PhpMethod $method
105
     * @param StructModel $struct
106
     * @return ClassMap
107
     */
108
    protected function addStructToClassMapList(PhpMethod $method, StructModel $struct)
109 66
    {
110
        if ($struct->isStruct() && !$struct->isRestriction()) {
111 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

111
            $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), /** @scrutinizer ignore-type */ $this->getStructName($struct)), 1));
Loading history...
112 66
        }
113 33
        return $this;
114 66
    }
115
    /**
116
     * work around for https://bugs.php.net/bug.php?id=69280
117
     * @param StructModel $struct
118
     * @return ClassMap
119
     */
120
    protected function getStructName(StructModel $struct)
121 66
    {
122
        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...
123 66
    }
124
}
125