Completed
Push — develop ( 0869de...14a867 )
by Mikaël
31:40
created

Method   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 97.73%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 14
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 157
ccs 43
cts 44
cp 0.9773
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getCleanName() 0 4 1
A getMethodName() 0 18 4
A getParameterType() 0 4 1
A setParameterType() 0 5 1
A getReturnType() 0 4 1
A setReturnType() 0 5 1
A getIsUnique() 0 4 1
A setIsUnique() 0 5 1
A getOwner() 0 4 1
A getReservedMethodsInstance() 0 4 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\Model;
4
5
use WsdlToPhp\PackageGenerator\Generator\Generator;
6
use WsdlToPhp\PackageGenerator\ConfigurationReader\ServiceReservedMethod;
7
8
/**
9
 * Class Method stands for an available operation described in the WSDL
10
 */
11
class Method extends AbstractModel
12
{
13
    /**
14
     * Type of the parameter for the operation
15
     * @var string
16
     */
17
    private $parameterType = '';
18
    /**
19
     * Type of the return value for the operation
20
     * @var string
21
     */
22
    private $returnType = '';
23
    /**
24
     * Indicates function is not alone with this name, then its name is contextualized based on its parameter(s)
25
     * @var bool
26
     */
27
    private $isUnique = true;
28
    /**
29
     * Generated method name stored as soon as it has been defined once
30
     * @var string
31
     */
32
    private $methodName = null;
33
    /**
34
     * Main constructor
35
     * @see AbstractModel::__construct()
36
     * @uses Method::setParameterType()
37
     * @uses Method::setReturnType()
38
     * @uses AbstractModel::setOwner()
39
     * @param Generator $generator
40
     * @param string $name the function name
41
     * @param string|array $parameterType the type/name of the parameter
42
     * @param string|array $returnType the type/name of the return value
43
     * @param Service $service defines the struct which owns this value
44
     * @param bool $isUnique defines if the method is unique or not
45
     */
46 500
    public function __construct(Generator $generator, $name, $parameterType, $returnType, Service $service, $isUnique = true)
47
    {
48 500
        parent::__construct($generator, $name);
49 375
        $this
50 500
            ->setParameterType($parameterType)
51 500
            ->setReturnType($returnType)
52 500
            ->setIsUnique($isUnique)
53 500
            ->setOwner($service);
54 500
    }
55
    /**
56
     * Method name can't starts with numbers
57
     * @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::getCleanName()
58
     * @return string
59
     */
60 500
    public function getCleanName($keepMultipleUnderscores = true)
61
    {
62 500
        return preg_replace('/^(\d+)([a-zA-Z0-9]*)$/', '_$2', parent::getCleanName($keepMultipleUnderscores));
63
    }
64
    /**
65
     * Returns the name of the method that is used to call the operation
66
     * It takes care of the fact that the method might not be the only one named as it is.
67
     * @uses Method::getCleanName()
68
     * @uses AbstractModel::replacePhpReservedKeyword()
69
     * @uses AbstractModel::getOwner()
70
     * @uses AbstractModel::getPackagedName()
71
     * @uses AbstractModel::uniqueName()
72
     * @uses Method::getOwner()
73
     * @uses Method::getParameterType()
74
     * @uses Method::getIsUnique()
75
     * @return string
76
     */
77 500
    public function getMethodName()
78
    {
79 500
        if (empty($this->methodName)) {
80 500
            $methodName = $this->getCleanName();
81 500
            if (!$this->getIsUnique()) {
82 12
                if (is_string($this->getParameterType())) {
83 12
                    $methodName .= ucfirst($this->getParameterType());
84 9
                } else {
85
                    $methodName .= '_' . md5(var_export($this->getParameterType(), true));
86
                }
87 9
            }
88 500
            $context = $this->getOwner()->getPackagedName();
89 500
            $methodName = $this->replaceReservedMethod($methodName, $context);
90 500
            $methodName = self::replacePhpReservedKeyword($methodName, $context);
91 500
            $this->methodName = self::uniqueName($methodName, $this->getOwner()->getPackagedName());
92 375
        }
93 500
        return $this->methodName;
94
    }
95
    /**
96
     * Returns the parameter type
97
     * @return string|string[]
98
     */
99 348
    public function getParameterType()
100
    {
101 348
        return $this->parameterType;
102
    }
103
    /**
104
     * Set the parameter type
105
     * @param string|string[]
106
     * @return Method
107
     */
108 500
    public function setParameterType($parameterType)
109
    {
110 500
        $this->parameterType = $parameterType;
111 500
        return $this;
112
    }
113
    /**
114
     * Returns the retrun type
115
     * @return string
116
     */
117 284
    public function getReturnType()
118
    {
119 284
        return $this->returnType;
120
    }
121
    /**
122
     * Set the retrun type
123
     * @param string|string[]
124
     * @return Method
125
     */
126 500
    public function setReturnType($returnType)
127
    {
128 500
        $this->returnType = $returnType;
129 500
        return $this;
130
    }
131
    /**
132
     * Returns the isUnique property
133
     * @return bool
134
     */
135 500
    public function getIsUnique()
136
    {
137 500
        return $this->isUnique;
138
    }
139
    /**
140
     * Set the isUnique property
141
     * @param bool
142
     * @return Method
143
     */
144 500
    public function setIsUnique($isUnique)
145
    {
146 500
        $this->isUnique = $isUnique;
147 500
        return $this;
148
    }
149
    /**
150
     * Returns the owner model object, meaning a Service object
151
     * @see AbstractModel::getOwner()
152
     * @uses AbstractModel::getOwner()
153
     * @return Service
154
     */
155 500
    public function getOwner()
156
    {
157 500
        return parent::getOwner();
158
    }
159
    /**
160
     * @param $filename
161
     * @return ServiceReservedMethod
162
     */
163 500
    public function getReservedMethodsInstance($filename = null)
164
    {
165 500
        return ServiceReservedMethod::instance($filename);
166
    }
167
}
168