Complex classes like Struct often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Struct, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class Struct extends AbstractModelFile |
||
21 | { |
||
22 | /** |
||
23 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getClassConstants() |
||
24 | */ |
||
25 | 104 | protected function getClassConstants(ConstantContainer $constants) |
|
26 | { |
||
27 | 104 | } |
|
28 | /** |
||
29 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getConstantAnnotationBlock() |
||
30 | */ |
||
31 | protected function getConstantAnnotationBlock(PhpConstant $constant) |
||
32 | { |
||
33 | } |
||
34 | /** |
||
35 | * @param bool $includeInheritanceAttributes include the attributes of parent class, default parent attributes are not included. If true, then the array is an associative array containing and index "attribute" for the StructAttribute object and an index "model" for the Struct object. |
||
36 | * @param bool $requiredFirst places the required attributes first, then the not required in order to have the _contrust method with the required attribute at first |
||
37 | * @return StructAttributeContainer |
||
38 | */ |
||
39 | 104 | protected function getModelAttributes($includeInheritanceAttributes = false, $requiredFirst = true) |
|
40 | { |
||
41 | 104 | return $this->getModel()->getAttributes($includeInheritanceAttributes, $requiredFirst); |
|
42 | } |
||
43 | /** |
||
44 | * @param PropertyContainer |
||
45 | */ |
||
46 | 132 | protected function getClassProperties(PropertyContainer $properties) |
|
47 | { |
||
48 | 132 | if ($this->getModel()->getAttributes()->count() > 0) { |
|
49 | 104 | foreach ($this->getModelAttributes() as $attribute) { |
|
50 | 104 | $properties->add(new PhpProperty($attribute->getCleanName(), PhpProperty::NO_VALUE)); |
|
51 | 104 | } |
|
52 | 104 | } |
|
53 | 132 | } |
|
54 | /** |
||
55 | * @return PhpAnnotationBlock |
||
56 | */ |
||
57 | 104 | protected function getPropertyAnnotationBlock(PhpProperty $property) |
|
58 | { |
||
59 | 104 | $annotationBlock = new PhpAnnotationBlock(); |
|
60 | 104 | $annotationBlock->addChild(sprintf('The %s', $property->getName())); |
|
61 | 104 | if (($attribute = $this->getModel()->getAttribute($property->getName())) instanceof StructAttributeModel) { |
|
62 | 104 | $this->defineModelAnnotationsFromWsdl($annotationBlock, $attribute); |
|
63 | 104 | $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_VAR, $this->getStructAttributeTypeSetAnnotation($attribute, true))); |
|
64 | 104 | } |
|
65 | 104 | return $annotationBlock; |
|
66 | } |
||
67 | /** |
||
68 | * @param MethodContainer |
||
69 | */ |
||
70 | 104 | protected function getClassMethods(MethodContainer $methods) |
|
71 | { |
||
72 | 104 | $this |
|
73 | 104 | ->addStructMethodConstruct($methods) |
|
74 | 104 | ->addStructMethodsSetAndGet($methods) |
|
75 | 104 | ->addStructMethodSetState($methods); |
|
76 | 104 | } |
|
77 | /** |
||
78 | * @param MethodContainer $methods |
||
79 | * @return Struct |
||
80 | */ |
||
81 | 104 | protected function addStructMethodConstruct(MethodContainer $methods) |
|
82 | { |
||
83 | 104 | $method = new PhpMethod(self::METHOD_CONSTRUCT, $this->getStructMethodParametersValues()); |
|
84 | 104 | $this->addStructMethodConstructBody($method); |
|
85 | 104 | $methods->add($method); |
|
86 | 104 | return $this; |
|
87 | } |
||
88 | /** |
||
89 | * @param PhpMethod $method |
||
90 | * @return Struct |
||
91 | */ |
||
92 | 104 | protected function addStructMethodConstructBody(PhpMethod $method) |
|
93 | { |
||
94 | 104 | $count = $this->getModelAttributes()->count(); |
|
95 | 104 | foreach ($this->getModelAttributes() as $index=>$attribute) { |
|
96 | 104 | if ($index === 0) { |
|
97 | 104 | $method->addChild('$this'); |
|
98 | 104 | } |
|
99 | 104 | $this->addStructMethodConstructBodyForAttribute($method, $attribute, $count - 1 === $index); |
|
100 | 104 | } |
|
101 | 104 | return $this; |
|
102 | } |
||
103 | /** |
||
104 | * @param PhpMethod $method |
||
105 | * @param StructAttributeModel $attribute |
||
106 | * @param bool $isLast |
||
107 | * @return Struct |
||
108 | */ |
||
109 | 104 | protected function addStructMethodConstructBodyForAttribute(PhpMethod $method, StructAttributeModel $attribute, $isLast) |
|
110 | { |
||
111 | 104 | $method->addChild($method->getIndentedString(sprintf('->%s($%s)%s', $attribute->getSetterName(), lcfirst($attribute->getCleanName()), $isLast ? ';' : ''), 1)); |
|
112 | 104 | return $this; |
|
113 | } |
||
114 | /** |
||
115 | * @return PhpFunctionParameter[] |
||
116 | */ |
||
117 | 104 | protected function getStructMethodParametersValues() |
|
118 | { |
||
119 | 104 | $parametersValues = array(); |
|
120 | 104 | foreach ($this->getModelAttributes() as $attribute) { |
|
121 | 104 | $parametersValues[] = $this->getStructMethodParameter($attribute, true); |
|
122 | 104 | } |
|
123 | 104 | return $parametersValues; |
|
124 | } |
||
125 | /** |
||
126 | * @param StructAttributeModel $attribute |
||
127 | * @param bool $lowCaseFirstLetter |
||
128 | * @param mixed $defaultValue |
||
129 | * @return PhpFunctionParameter |
||
130 | */ |
||
131 | 104 | protected function getStructMethodParameter(StructAttributeModel $attribute, $lowCaseFirstLetter = false, $defaultValue = null) |
|
132 | { |
||
133 | try { |
||
134 | 104 | return new PhpFunctionParameter($lowCaseFirstLetter ? lcfirst($attribute->getCleanName()) : $attribute->getCleanName(), isset($defaultValue) ? $defaultValue : $attribute->getDefaultValue(), $this->getStructMethodParameterType($attribute)); |
|
135 | } catch (\InvalidArgumentException $exception) { |
||
136 | throw new \InvalidArgumentException(sprintf('Unable to create function parameter for struct "%s" with type "%s" for attribute "%s"', $this->getModel()->getName(), var_export($this->getStructMethodParameterType($attribute), true), $attribute->getName()), __LINE__, $exception); |
||
137 | } |
||
138 | } |
||
139 | /** |
||
140 | * @param StructAttributeModel $attribute |
||
141 | * @param bool $returnArrayType |
||
142 | * @return string|null |
||
143 | */ |
||
144 | 104 | protected function getStructMethodParameterType(StructAttributeModel $attribute, $returnArrayType = true) |
|
145 | { |
||
146 | 104 | return self::getValidType($this->getStructAttributeTypeHint($attribute, $returnArrayType), null); |
|
147 | } |
||
148 | /** |
||
149 | * @param MethodContainer $methods |
||
150 | * @return Struct |
||
151 | */ |
||
152 | 104 | protected function addStructMethodsSetAndGet(MethodContainer $methods) |
|
153 | { |
||
154 | 104 | foreach ($this->getModelAttributes() as $attribute) { |
|
155 | 104 | $this |
|
156 | 104 | ->addStructMethodGet($methods, $attribute) |
|
157 | 104 | ->addStructMethodSet($methods, $attribute) |
|
158 | 104 | ->addStructMethodAddTo($methods, $attribute); |
|
159 | 104 | } |
|
160 | 104 | return $this; |
|
161 | } |
||
162 | /** |
||
163 | * @param MethodContainer $methods |
||
164 | * @param StructAttributeModel $attribute |
||
165 | * @return Struct |
||
166 | */ |
||
167 | 104 | protected function addStructMethodAddTo(MethodContainer $methods, StructAttributeModel $attribute) |
|
168 | { |
||
169 | 104 | if ($attribute->isArray()) { |
|
170 | 60 | $method = new PhpMethod(sprintf('addTo%s', ucfirst($attribute->getCleanName())), array( |
|
171 | 60 | new PhpFunctionParameter('item', PhpFunctionParameter::NO_VALUE, $this->getStructMethodParameterType($attribute, false)), |
|
172 | 60 | )); |
|
173 | 60 | $this->addStructMethodAddToBody($method, $attribute); |
|
174 | 60 | $methods->add($method); |
|
175 | 60 | } |
|
176 | 104 | return $this; |
|
177 | } |
||
178 | /** |
||
179 | * @param PhpMethod $method |
||
180 | * @param StructAttributeModel $attribute |
||
181 | * @return Struct |
||
182 | */ |
||
183 | 60 | protected function addStructMethodAddToBody(PhpMethod $method, StructAttributeModel $attribute) |
|
184 | { |
||
185 | 60 | if ($this->getGenerator()->getOptionValidation()) { |
|
186 | 60 | $rules = new Rules($this, $method, $attribute); |
|
187 | 60 | $rules->applyRules('item', true); |
|
188 | 60 | } |
|
189 | $method |
||
190 | 60 | ->addChild(sprintf('$this->%s[] = $item;', $attribute->getCleanName())) |
|
191 | 60 | ->addChild('return $this;'); |
|
192 | 60 | return $this; |
|
193 | } |
||
194 | /** |
||
195 | * @param MethodContainer $methods |
||
196 | * @param StructAttributeModel $attribute |
||
197 | * @return Struct |
||
198 | */ |
||
199 | 104 | protected function addStructMethodSet(MethodContainer $methods, StructAttributeModel $attribute) |
|
200 | { |
||
201 | 104 | $method = new PhpMethod($attribute->getSetterName(), array( |
|
202 | 104 | $this->getStructMethodParameter($attribute, true, null), |
|
203 | 104 | )); |
|
204 | 104 | $this->addStructMethodSetBody($method, $attribute); |
|
205 | 104 | $methods->add($method); |
|
206 | 104 | return $this; |
|
207 | } |
||
208 | /** |
||
209 | * @param PhpMethod $method |
||
210 | * @param StructAttributeModel $attribute |
||
211 | * @return Struct |
||
212 | */ |
||
213 | 104 | protected function addStructMethodSetBody(PhpMethod $method, StructAttributeModel $attribute) |
|
214 | { |
||
215 | 104 | if ($this->getGenerator()->getOptionValidation()) { |
|
216 | 100 | $rules = new Rules($this, $method, $attribute); |
|
217 | 100 | $rules->applyRules(lcfirst($attribute->getCleanName())); |
|
218 | 100 | } |
|
219 | 104 | return $this |
|
220 | 104 | ->addStructMethodSetBodyAssignment($method, $attribute) |
|
221 | 104 | ->addStructMethodSetBodyReturn($method); |
|
222 | } |
||
223 | /** |
||
224 | * @param PhpMethod $method |
||
225 | * @param StructAttributeModel $attribute |
||
226 | * @return Struct |
||
227 | */ |
||
228 | 104 | protected function addStructMethodSetBodyAssignment(PhpMethod $method, StructAttributeModel $attribute) |
|
229 | { |
||
230 | 104 | $parameterName = lcfirst($attribute->getCleanName()); |
|
231 | 104 | if ($attribute->getRemovableFromRequest()) { |
|
232 | $method |
||
233 | 20 | ->addChild(sprintf('if (is_null($%1$s) || (is_array($%1$s) && empty($%1$s))) {', $parameterName)) |
|
234 | 20 | ->addChild($method->getIndentedString(sprintf('unset($this->%1$s%2$s);', $attribute->getCleanName(), $attribute->nameIsClean() ? '' : sprintf(', $this->{\'%s\'}', addslashes($attribute->getName()))), 1)) |
|
235 | 20 | ->addChild('} else {') |
|
236 | 20 | ->addChild($method->getIndentedString($this->getStructMethodSetBodyAssignment($attribute, $parameterName), 1)) |
|
237 | 20 | ->addChild('}'); |
|
238 | 20 | } else { |
|
239 | 100 | $method->addChild($this->getStructMethodSetBodyAssignment($attribute, $parameterName)); |
|
240 | } |
||
241 | 104 | return $this; |
|
242 | } |
||
243 | /** |
||
244 | * @param PhpMethod $method |
||
245 | * @return Struct |
||
246 | */ |
||
247 | 104 | protected function addStructMethodSetBodyReturn(PhpMethod $method) |
|
248 | { |
||
249 | 104 | $method->addChild('return $this;'); |
|
250 | 104 | return $this; |
|
251 | } |
||
252 | /** |
||
253 | * @param PhpMethod $method |
||
254 | * @param StructAttributeModel $attribute |
||
255 | * @param string $parameterName |
||
256 | * @return Struct |
||
257 | */ |
||
258 | 12 | protected function addStructMethodSetBodyForRestriction(PhpMethod $method, StructAttributeModel $attribute, $parameterName = null) |
|
259 | { |
||
260 | 12 | if (($model = $this->getRestrictionFromStructAttribute($attribute)) instanceof StructModel) { |
|
261 | 12 | $parameterName = empty($parameterName) ? lcfirst($attribute->getCleanName()) : $parameterName; |
|
262 | $method |
||
263 | 12 | ->addChild(sprintf('if (!%s::%s($%s)) {', $model->getPackagedName(true), StructEnum::METHOD_VALUE_IS_VALID, $parameterName)) |
|
264 | 12 | ->addChild($method->getIndentedString(sprintf('throw new \InvalidArgumentException(sprintf(\'Value "%%s" is invalid, please use one of: %%s\', $%s, implode(\', \', %s::%s())), __LINE__);', $parameterName, $model->getPackagedName(true), StructEnum::METHOD_GET_VALID_VALUES), 1)) |
|
265 | 12 | ->addChild('}'); |
|
266 | 12 | } |
|
267 | 12 | return $this; |
|
268 | } |
||
269 | /** |
||
270 | * @param StructAttributeModel $attribute |
||
271 | * @param string $parameterName |
||
272 | * @return string |
||
273 | */ |
||
274 | 104 | protected function getStructMethodSetBodyAssignment(StructAttributeModel $attribute, $parameterName) |
|
275 | { |
||
276 | 104 | if ($attribute->nameIsClean()) { |
|
277 | 104 | $assignment = sprintf('$this->%s = $%s;', $attribute->getName(), $parameterName); |
|
278 | 104 | } else { |
|
279 | $assignment = sprintf('$this->%s = $this->{\'%s\'} = $%s;', $attribute->getCleanName(), addslashes($attribute->getName()), $parameterName); |
||
280 | } |
||
281 | 104 | return $assignment; |
|
282 | } |
||
283 | /** |
||
284 | * @param PhpMethod $method |
||
285 | * @param StructAttributeModel $attribute |
||
286 | * @param string $thisAccess |
||
287 | * @return Struct |
||
288 | */ |
||
289 | 104 | protected function addStructMethodGetBody(PhpMethod $method, StructAttributeModel $attribute, $thisAccess) |
|
295 | /** |
||
296 | * @param PhpMethod $method |
||
297 | * @param StructAttributeModel $attribute |
||
298 | * @param string $thisAccess |
||
299 | * @return Struct |
||
300 | */ |
||
301 | 104 | protected function addStructMethodGetBodyForXml(PhpMethod $method, StructAttributeModel $attribute, $thisAccess) |
|
316 | /** |
||
317 | * @param PhpMethod $method |
||
318 | * @param StructAttributeModel $attribute |
||
319 | * @param string $thisAccess |
||
320 | * @return Struct |
||
321 | */ |
||
322 | 104 | protected function addStructMethodGetBodyReturn(PhpMethod $method, StructAttributeModel $attribute, $thisAccess) |
|
337 | /** |
||
338 | * @param MethodContainer $methods |
||
339 | * @param StructAttributeModel $attribute |
||
340 | * @return Struct |
||
341 | */ |
||
342 | 104 | protected function addStructMethodGet(MethodContainer $methods, StructAttributeModel $attribute) |
|
354 | /** |
||
355 | * @param StructAttributeModel $attribute |
||
356 | * @return PhpFunctionParameter[] |
||
357 | */ |
||
358 | 104 | protected function getStructMethodGetParameters(StructAttributeModel $attribute) |
|
359 | { |
||
360 | 104 | $parameters = array(); |
|
361 | 104 | if ($attribute->isXml()) { |
|
362 | 4 | $parameters[] = new PhpFunctionParameter('asString', true); |
|
363 | 4 | } |
|
364 | 104 | return $parameters; |
|
365 | } |
||
366 | /** |
||
367 | * @param MethodContainer $methods |
||
368 | * @return Struct |
||
369 | */ |
||
370 | 104 | protected function addStructMethodSetState(MethodContainer $methods) |
|
371 | { |
||
372 | 104 | $method = new PhpMethod(self::METHOD_SET_STATE, array( |
|
373 | 104 | new PhpFunctionParameter('array', PhpFunctionParameter::NO_VALUE, 'array'), |
|
374 | 104 | ), PhpMethod::ACCESS_PUBLIC, false, true); |
|
375 | 104 | $method->addChild(sprintf('return parent::__set_state($array);')); |
|
376 | 104 | $methods->add($method); |
|
377 | 104 | return $this; |
|
378 | } |
||
379 | /** |
||
380 | * @return PhpAnnotationBlock|null |
||
381 | */ |
||
382 | 104 | protected function getMethodAnnotationBlock(PhpMethod $method) |
|
383 | { |
||
384 | 104 | return $this->getStructMethodAnnotationBlock($method); |
|
385 | } |
||
386 | /** |
||
387 | * @param PhpMethod $method |
||
388 | * @return PhpAnnotationBlock|null |
||
389 | */ |
||
390 | 104 | protected function getStructMethodAnnotationBlock(PhpMethod $method) |
|
391 | { |
||
392 | 104 | $annotationBlock = null; |
|
393 | 104 | switch ($method->getName()) { |
|
394 | 104 | case self::METHOD_CONSTRUCT: |
|
395 | 84 | $annotationBlock = $this->getStructMethodConstructAnnotationBlock(); |
|
396 | 84 | break; |
|
397 | 104 | case self::METHOD_SET_STATE: |
|
398 | 84 | $annotationBlock = $this->getStructMethodSetStateAnnotationBlock(); |
|
399 | 84 | break; |
|
400 | 104 | case strpos($method->getName(), 'get') === 0: |
|
401 | 104 | case strpos($method->getName(), 'set') === 0: |
|
402 | 104 | $annotationBlock = $this->getStructMethodsSetAndGetAnnotationBlock($method); |
|
403 | 104 | break; |
|
404 | 60 | case strpos($method->getName(), 'addTo') === 0: |
|
405 | 60 | $annotationBlock = $this->getStructMethodsAddToAnnotationBlock($method); |
|
406 | 60 | break; |
|
407 | 104 | } |
|
408 | 104 | return $annotationBlock; |
|
409 | } |
||
410 | /** |
||
411 | * @return PhpAnnotationBlock |
||
412 | */ |
||
413 | 104 | protected function getStructMethodConstructAnnotationBlock() |
|
414 | { |
||
415 | 104 | $annotationBlock = new PhpAnnotationBlock(array( |
|
416 | 104 | sprintf('Constructor method for %s', $this->getModel()->getName()), |
|
417 | 104 | )); |
|
418 | 104 | $this->addStructPropertiesToAnnotationBlock($annotationBlock); |
|
419 | 104 | return $annotationBlock; |
|
420 | } |
||
421 | /** |
||
422 | * @return PhpAnnotationBlock |
||
423 | */ |
||
424 | 104 | protected function getStructMethodSetStateAnnotationBlock() |
|
425 | { |
||
426 | 104 | return new PhpAnnotationBlock(array( |
|
427 | 104 | 'Method called when an object has been exported with var_export() functions', |
|
428 | 104 | 'It allows to return an object instantiated with the values', |
|
429 | 104 | new PhpAnnotation(self::ANNOTATION_SEE, sprintf('%s::__set_state()', $this->getModel()->getExtends(true))), |
|
430 | 104 | new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::__set_state()', $this->getModel()->getExtends(true))), |
|
431 | 104 | new PhpAnnotation(self::ANNOTATION_PARAM, 'array $array the exported values'), |
|
432 | 104 | new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true)), |
|
433 | 104 | )); |
|
434 | } |
||
435 | /** |
||
436 | * @param PhpMethod $method |
||
437 | * @return PhpAnnotationBlock |
||
438 | */ |
||
439 | 104 | protected function getStructMethodsSetAndGetAnnotationBlock(PhpMethod $method) |
|
440 | { |
||
441 | 104 | $parameters = $method->getParameters(); |
|
442 | 104 | $setOrGet = strtolower(substr($method->getName(), 0, 3)); |
|
443 | 104 | $parameter = array_shift($parameters); |
|
444 | /** |
||
445 | * Only set parameter must be based on a potential PhpFunctionParameter |
||
446 | */ |
||
447 | 104 | if ($parameter instanceof PhpFunctionParameter && $setOrGet === 'set') { |
|
448 | 104 | $parameterName = ucfirst($parameter->getName()); |
|
449 | 104 | } else { |
|
450 | 104 | $parameterName = substr($method->getName(), 3); |
|
451 | } |
||
452 | 104 | $attribute = $this->getModel()->getAttribute($parameterName); |
|
453 | 104 | if (!$attribute instanceof StructAttributeModel) { |
|
454 | 52 | $parameterName = lcfirst($parameterName); |
|
455 | 52 | $attribute = $this->getModel()->getAttribute($parameterName); |
|
456 | 52 | } |
|
457 | 104 | $setValueAnnotation = '%s %s value'; |
|
458 | 104 | $annotationBlock = new PhpAnnotationBlock(); |
|
459 | 104 | if ($attribute instanceof StructAttributeModel) { |
|
460 | 104 | $annotationBlock->addChild(sprintf($setValueAnnotation, ucfirst($setOrGet), $parameterName)); |
|
461 | 104 | $this->addStructMethodsSetAndGetAnnotationBlockFromStructAttribute($setOrGet, $annotationBlock, $attribute); |
|
462 | 104 | } elseif (empty($attribute)) { |
|
463 | 4 | $annotationBlock->addChild(sprintf($setValueAnnotation, ucfirst($setOrGet), lcfirst($parameterName))); |
|
464 | 4 | $this->addStructMethodsSetAndGetAnnotationBlockFromScalar($setOrGet, $annotationBlock, $parameterName); |
|
465 | 4 | } |
|
466 | 104 | return $annotationBlock; |
|
467 | } |
||
468 | /** |
||
469 | * @param string $setOrGet |
||
470 | * @param PhpAnnotationBlock $annotationBlock |
||
471 | * @param StructAttributeModel $attribute |
||
472 | * @return Struct |
||
473 | */ |
||
474 | 104 | protected function addStructMethodsSetAndGetAnnotationBlockFromStructAttribute($setOrGet, PhpAnnotationBlock $annotationBlock, StructAttributeModel $attribute) |
|
475 | { |
||
476 | switch ($setOrGet) { |
||
477 | 104 | case 'set': |
|
478 | 104 | if ($attribute->getRemovableFromRequest()) { |
|
479 | 20 | $annotationBlock->addChild('This property is removable from request (nillable=true+minOccurs=0), therefore if the value assigned to this property is null, it is removed from this object'); |
|
480 | 20 | } |
|
481 | 104 | if (($model = $this->getRestrictionFromStructAttribute($attribute)) instanceof StructModel && !$this->getModel()->isArray()) { |
|
482 | $annotationBlock |
||
483 | 48 | ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $model->getPackagedName(true), StructEnum::METHOD_VALUE_IS_VALID))) |
|
484 | 48 | ->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $model->getPackagedName(true), StructEnum::METHOD_GET_VALID_VALUES))) |
|
485 | 48 | ->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, '\InvalidArgumentException')); |
|
486 | 104 | } elseif ($attribute->isArray()) { |
|
487 | 60 | $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_THROWS, '\InvalidArgumentException')); |
|
488 | 60 | } |
|
489 | 104 | $this->addStructMethodsSetAnnotationBlock($annotationBlock, $this->getStructAttributeTypeSetAnnotation($attribute), lcfirst($attribute->getCleanName())); |
|
490 | 104 | break; |
|
491 | 104 | case 'get': |
|
492 | 104 | if ($attribute->getRemovableFromRequest()) { |
|
493 | 20 | $annotationBlock->addChild('An additional test has been added (isset) before returning the property value as this property may have been unset before, due to the fact that this property is removable from the request (nillable=true+minOccurs=0)'); |
|
494 | 20 | } |
|
495 | 104 | $this |
|
496 | 104 | ->addStructMethodsGetAnnotationBlockFromXmlAttribute($annotationBlock, $attribute) |
|
497 | 104 | ->addStructMethodsGetAnnotationBlock($annotationBlock, $this->getStructAttributeTypeGetAnnotation($attribute)); |
|
498 | 104 | break; |
|
499 | } |
||
500 | 104 | return $this; |
|
501 | } |
||
502 | /** |
||
503 | * @param string $setOrGet |
||
504 | * @param PhpAnnotationBlock $annotationBlock |
||
505 | * @param string $attributeName |
||
506 | * @return Struct |
||
507 | */ |
||
508 | 4 | protected function addStructMethodsSetAndGetAnnotationBlockFromScalar($setOrGet, PhpAnnotationBlock $annotationBlock, $attributeName) |
|
520 | /** |
||
521 | * @param PhpAnnotationBlock $annotationBlock |
||
522 | * @param string $type |
||
523 | * @param string $name |
||
524 | * @return Struct |
||
525 | */ |
||
526 | 104 | protected function addStructMethodsSetAnnotationBlock(PhpAnnotationBlock $annotationBlock, $type, $name) |
|
527 | { |
||
528 | $annotationBlock |
||
529 | 104 | ->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $type, $name))) |
|
530 | 104 | ->addChild(new PhpAnnotation(self::ANNOTATION_RETURN, $this->getModel()->getPackagedName(true))); |
|
531 | 104 | return $this; |
|
532 | } |
||
533 | /** |
||
534 | * @param PhpAnnotationBlock $annotationBlock |
||
535 | * @param string $attributeType |
||
536 | * @return Struct |
||
537 | */ |
||
538 | 104 | protected function addStructMethodsGetAnnotationBlock(PhpAnnotationBlock $annotationBlock, $attributeType) |
|
543 | /** |
||
544 | * @param PhpAnnotationBlock $annotationBlock |
||
545 | * @param StructAttributeModel $attribute |
||
546 | * @return Struct |
||
547 | */ |
||
548 | 104 | protected function addStructMethodsGetAnnotationBlockFromXmlAttribute(PhpAnnotationBlock $annotationBlock, StructAttributeModel $attribute) |
|
561 | /** |
||
562 | * @param PhpAnnotationBlock $annotationBlock |
||
563 | * @return Struct |
||
564 | */ |
||
565 | 104 | protected function addStructPropertiesToAnnotationBlock(PhpAnnotationBlock $annotationBlock) |
|
566 | { |
||
567 | 104 | return $this |
|
568 | 104 | ->addStructPropertiesToAnnotationBlockUses($annotationBlock) |
|
569 | 104 | ->addStructPropertiesToAnnotationBlockParams($annotationBlock); |
|
570 | } |
||
571 | /** |
||
572 | * @param PhpAnnotationBlock $annotationBlock |
||
573 | * @return Struct |
||
574 | */ |
||
575 | 104 | protected function addStructPropertiesToAnnotationBlockUses(PhpAnnotationBlock $annotationBlock) |
|
576 | { |
||
577 | 104 | foreach ($this->getModelAttributes() as $attribute) { |
|
578 | 104 | $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_USES, sprintf('%s::%s()', $this->getModel()->getPackagedName(), $attribute->getSetterName()))); |
|
579 | 104 | } |
|
580 | 104 | return $this; |
|
581 | } |
||
582 | /** |
||
583 | * @param PhpAnnotationBlock $annotationBlock |
||
584 | * @return Struct |
||
585 | */ |
||
586 | 104 | protected function addStructPropertiesToAnnotationBlockParams(PhpAnnotationBlock $annotationBlock) |
|
587 | { |
||
588 | 104 | foreach ($this->getModelAttributes() as $attribute) { |
|
589 | 104 | $annotationBlock->addChild(new PhpAnnotation(self::ANNOTATION_PARAM, sprintf('%s $%s', $this->getStructAttributeTypeSetAnnotation($attribute), lcfirst($attribute->getCleanName())))); |
|
590 | 104 | } |
|
591 | 104 | return $this; |
|
593 | /** |
||
594 | * @param PhpMethod $method |
||
595 | * @return PhpAnnotationBlock |
||
596 | */ |
||
597 | 60 | protected function getStructMethodsAddToAnnotationBlock(PhpMethod $method) |
|
620 | /** |
||
621 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::getModel() |
||
622 | * @return StructModel |
||
623 | */ |
||
624 | 152 | public function getModel() |
|
628 | /** |
||
629 | * @see \WsdlToPhp\PackageGenerator\File\AbstractModelFile::setModel() |
||
630 | * @throws \InvalidaArgumentException |
||
631 | * @param AbstractModel $model |
||
632 | * @return StructArray |
||
633 | */ |
||
634 | 152 | public function setModel(AbstractModel $model) |
|
641 | } |
||
642 |