|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PhpGenerator\Element; |
|
6
|
|
|
|
|
7
|
|
|
class PhpMethod extends PhpFunction |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var bool |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $final; |
|
13
|
|
|
/** |
|
14
|
|
|
* @var bool |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $static; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var bool |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $abstract; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var bool |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $hasBody; |
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $name |
|
27
|
|
|
* @param string[]|PhpFunctionParameter[] $parameters |
|
28
|
|
|
* @param string $access |
|
29
|
|
|
* @param bool $abstract |
|
30
|
|
|
* @param bool $static |
|
31
|
|
|
* @param bool $final |
|
32
|
|
|
* @param bool $hasBody |
|
33
|
|
|
*/ |
|
34
|
58 |
|
public function __construct(string $name, array $parameters = [], string $access = parent::ACCESS_PUBLIC, bool $abstract = false, bool $static = false, bool $final = false, bool $hasBody = true) |
|
35
|
|
|
{ |
|
36
|
58 |
|
parent::__construct($name, $parameters); |
|
37
|
|
|
$this |
|
38
|
58 |
|
->setAccess($access) |
|
39
|
58 |
|
->setAbstract($abstract) |
|
40
|
58 |
|
->setStatic($static) |
|
41
|
58 |
|
->setFinal($final) |
|
42
|
58 |
|
->setHasBody($hasBody); |
|
43
|
58 |
|
} |
|
44
|
|
|
/** |
|
45
|
|
|
* @param bool $abstract |
|
46
|
|
|
* @return PhpMethod |
|
47
|
|
|
*/ |
|
48
|
58 |
|
public function setAbstract(bool $abstract): PhpMethod |
|
49
|
|
|
{ |
|
50
|
58 |
|
$this->abstract = $abstract; |
|
51
|
58 |
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
/** |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
40 |
|
public function getAbstract(): bool |
|
57
|
|
|
{ |
|
58
|
40 |
|
return $this->abstract; |
|
59
|
|
|
} |
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
40 |
|
protected function getPhpAbstract(): string |
|
64
|
|
|
{ |
|
65
|
40 |
|
return $this->getAbstract() === true ? 'abstract ' : ''; |
|
66
|
|
|
} |
|
67
|
|
|
/** |
|
68
|
|
|
* @param bool $final |
|
69
|
|
|
* @return PhpMethod |
|
70
|
|
|
*/ |
|
71
|
58 |
|
public function setFinal(bool $final): PhpMethod |
|
72
|
|
|
{ |
|
73
|
58 |
|
$this->final = $final; |
|
74
|
58 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
/** |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
40 |
|
public function getFinal(): bool |
|
80
|
|
|
{ |
|
81
|
40 |
|
return $this->final; |
|
82
|
|
|
} |
|
83
|
|
|
/** |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
40 |
|
protected function getPhpFinal(): string |
|
87
|
|
|
{ |
|
88
|
40 |
|
return $this->getFinal() === true ? 'final ' : ''; |
|
89
|
|
|
} |
|
90
|
|
|
/** |
|
91
|
|
|
* @param bool $static |
|
92
|
|
|
* @return PhpMethod |
|
93
|
|
|
*/ |
|
94
|
58 |
|
public function setStatic(bool $static): PhpMethod |
|
95
|
|
|
{ |
|
96
|
58 |
|
$this->static = $static; |
|
97
|
58 |
|
return $this; |
|
98
|
|
|
} |
|
99
|
|
|
/** |
|
100
|
|
|
* @return bool |
|
101
|
|
|
*/ |
|
102
|
40 |
|
public function getStatic(): bool |
|
103
|
|
|
{ |
|
104
|
40 |
|
return $this->static; |
|
105
|
|
|
} |
|
106
|
|
|
/** |
|
107
|
|
|
* @return string |
|
108
|
|
|
*/ |
|
109
|
40 |
|
protected function getPhpStatic(): string |
|
110
|
|
|
{ |
|
111
|
40 |
|
return $this->getStatic() === true ? 'static ' : ''; |
|
112
|
|
|
} |
|
113
|
|
|
/** |
|
114
|
|
|
* @param bool $hasBody |
|
115
|
|
|
* @return PhpMethod |
|
116
|
|
|
*/ |
|
117
|
58 |
|
public function setHasBody(bool $hasBody): PhpMethod |
|
118
|
|
|
{ |
|
119
|
58 |
|
$this->hasBody = $hasBody; |
|
120
|
58 |
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
/** |
|
123
|
|
|
* @return bool |
|
124
|
|
|
*/ |
|
125
|
48 |
|
public function getHasBody(): bool |
|
126
|
|
|
{ |
|
127
|
48 |
|
return $this->hasBody; |
|
128
|
|
|
} |
|
129
|
|
|
/** |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
40 |
|
protected function getPhpDeclarationEnd(): string |
|
133
|
|
|
{ |
|
134
|
40 |
|
return ($this->getHasBody() === false || $this->getAbstract() === true) ? ';' : ''; |
|
135
|
|
|
} |
|
136
|
|
|
/** |
|
137
|
|
|
* @see \WsdlToPhp\PhpGenerator\Element\AbstractAccessRestrictedElement::getPhpDeclaration() |
|
138
|
|
|
* @return string |
|
139
|
|
|
*/ |
|
140
|
40 |
|
public function getPhpDeclaration(): string |
|
141
|
|
|
{ |
|
142
|
40 |
|
return sprintf('%s%s%s%sfunction %s(%s)%s', $this->getPhpFinal(), $this->getPhpAbstract(), $this->getPhpAccess(), $this->getPhpStatic(), $this->getPhpName(), $this->getPhpParameters(), $this->getPhpDeclarationEnd()); |
|
143
|
|
|
} |
|
144
|
|
|
/** |
|
145
|
|
|
* indicates if the current element has accessibility constraint |
|
146
|
|
|
* @return bool |
|
147
|
|
|
*/ |
|
148
|
40 |
|
public function hasAccessibilityConstraint(): bool |
|
149
|
|
|
{ |
|
150
|
40 |
|
return true; |
|
151
|
|
|
} |
|
152
|
|
|
/** |
|
153
|
|
|
* Allows to generate content before children content is generated |
|
154
|
|
|
* @param int $indentation |
|
155
|
|
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
8 |
|
public function getLineBeforeChildren(int $indentation = null): string |
|
158
|
|
|
{ |
|
159
|
8 |
|
if ($this->getHasBody() === true) { |
|
160
|
2 |
|
return parent::getLineBeforeChildren($indentation); |
|
161
|
|
|
} |
|
162
|
6 |
|
return ''; |
|
163
|
|
|
} |
|
164
|
|
|
/** |
|
165
|
|
|
* Allows to generate content after children content is generated |
|
166
|
|
|
* @param int $indentation |
|
167
|
|
|
* @return string |
|
168
|
|
|
*/ |
|
169
|
8 |
|
public function getLineAfterChildren(int $indentation = null): string |
|
170
|
|
|
{ |
|
171
|
8 |
|
if ($this->getHasBody() === true) { |
|
172
|
2 |
|
return parent::getLineAfterChildren($indentation); |
|
173
|
|
|
} |
|
174
|
6 |
|
return ''; |
|
175
|
|
|
} |
|
176
|
|
|
/** |
|
177
|
|
|
* @see \WsdlToPhp\PhpGenerator\Element\AbstractElement::getChildren() |
|
178
|
|
|
* @return array |
|
179
|
|
|
*/ |
|
180
|
28 |
|
public function getChildren(): array |
|
181
|
|
|
{ |
|
182
|
28 |
|
if ($this->getHasBody() === true) { |
|
183
|
22 |
|
return parent::getChildren(); |
|
184
|
|
|
} |
|
185
|
6 |
|
return []; |
|
186
|
|
|
} |
|
187
|
|
|
/** |
|
188
|
|
|
* Allows to indicate that children are contained by brackets, |
|
189
|
|
|
* in the case the method returns true, getBracketBeforeChildren |
|
190
|
|
|
* is called instead of getLineBeforeChildren and getBracketAfterChildren |
|
191
|
|
|
* is called instead of getLineAfterChildren, but be aware that these methods |
|
192
|
|
|
* call the two others |
|
193
|
|
|
* @return bool |
|
194
|
|
|
*/ |
|
195
|
24 |
|
public function useBracketsForChildren(): bool |
|
196
|
|
|
{ |
|
197
|
24 |
|
return $this->getHasBody(); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|