Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.39% |
61 / 62 |
|
92.31% |
12 / 13 |
CRAP | |
0.00% |
0 / 1 |
OperationAnnotationBlock | |
98.39% |
61 / 62 |
|
92.31% |
12 / 13 |
24 | |
0.00% |
0 / 1 |
addAnnotationBlockForOperationMethod | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
addOperationMethodDeclaration | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
addOperationMethodMetaInformation | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
4 | |||
getSoapHeaderTypesTypes | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getSoapHeaderTypeType | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
addOperationMethodUses | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
addOperationMethodParam | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addOperationMethodParamFromArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
addOperationMethodParamFromModel | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
getOperationMethodParam | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
addOperationMethodParamFromString | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
addOperationMethodReturn | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getOperationMethodReturnType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace WsdlToPhp\PackageGenerator\File; |
6 | |
7 | use WsdlToPhp\PackageGenerator\File\Utils as FileUtils; |
8 | use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
9 | use WsdlToPhp\PackageGenerator\Model\Method as MethodModel; |
10 | use WsdlToPhp\PackageGenerator\Parser\Wsdl\TagHeader; |
11 | use WsdlToPhp\PhpGenerator\Element\PhpAnnotation; |
12 | use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock; |
13 | |
14 | final class OperationAnnotationBlock extends AbstractOperation |
15 | { |
16 | public function addAnnotationBlockForOperationMethod(PhpAnnotationBlock $annotationBlock): self |
17 | { |
18 | $this |
19 | ->addOperationMethodDeclaration($annotationBlock) |
20 | ->addOperationMethodMetaInformation($annotationBlock) |
21 | ->addOperationMethodUses($annotationBlock) |
22 | ->addOperationMethodParam($annotationBlock) |
23 | ->addOperationMethodReturn($annotationBlock) |
24 | ; |
25 | |
26 | return $this; |
27 | } |
28 | |
29 | protected function addOperationMethodDeclaration(PhpAnnotationBlock $annotationBlock): self |
30 | { |
31 | $annotationBlock->addChild(sprintf('Method to call the operation originally named %s', $this->getMethod()->getName())); |
32 | if (!$this->getMethod()->isUnique()) { |
33 | $annotationBlock->addChild('This method has been renamed because it is defined several times but with different signature'); |
34 | } |
35 | |
36 | return $this; |
37 | } |
38 | |
39 | protected function addOperationMethodMetaInformation(PhpAnnotationBlock $annotationBlock): self |
40 | { |
41 | $soapHeaderNames = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_NAMES, []); |
42 | $soapHeaderTypes = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_TYPES, []); |
43 | $soapHeaderNamespaces = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_NAMESPACES, []); |
44 | $soapHeaders = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADERS, []); |
45 | if (!empty($soapHeaderNames) && !empty($soapHeaderTypes) && !empty($soapHeaderNamespaces)) { |
46 | $annotationBlock |
47 | ->addChild('Meta information extracted from the WSDL') |
48 | ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNames: %s', implode(', ', $soapHeaderNames)), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
49 | ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNamespaces: %s', implode(', ', $soapHeaderNamespaces)), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
50 | ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderTypes: %s', implode(', ', $this->getSoapHeaderTypesTypes($soapHeaderTypes))), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
51 | ->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaders: %s', implode(', ', $soapHeaders)), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
52 | ; |
53 | } |
54 | FileUtils::defineModelAnnotationsFromWsdl($annotationBlock, $this->getMethod(), [ |
55 | TagHeader::META_SOAP_HEADER_NAMES, |
56 | TagHeader::META_SOAP_HEADER_NAMESPACES, |
57 | TagHeader::META_SOAP_HEADER_TYPES, |
58 | TagHeader::META_SOAP_HEADERS, |
59 | ]); |
60 | |
61 | return $this; |
62 | } |
63 | |
64 | protected function getSoapHeaderTypesTypes(array $soapHeaderTypes): array |
65 | { |
66 | $soapHeaderTypesTypes = []; |
67 | foreach ($soapHeaderTypes as $soapHeaderType) { |
68 | $soapHeaderTypesTypes[] = $this->getSoapHeaderTypeType($soapHeaderType, true); |
69 | } |
70 | |
71 | return $soapHeaderTypesTypes; |
72 | } |
73 | |
74 | protected function getSoapHeaderTypeType(string $soapHeaderType, bool $namespaced = false): string |
75 | { |
76 | $type = $soapHeaderType; |
77 | $model = $this->getModelByName($soapHeaderType); |
78 | if ($model instanceof AbstractModel) { |
79 | $type = $model->getPackagedName($namespaced); |
80 | } |
81 | |
82 | return $type; |
83 | } |
84 | |
85 | protected function addOperationMethodUses(PhpAnnotationBlock $annotationBlock): self |
86 | { |
87 | $annotationBlock |
88 | ->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_USES, sprintf('%s::getSoapClient()', $this->getMethod()->getOwner()->getExtends(true)))) |
89 | ->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_USES, sprintf('%s::setResult()', $this->getMethod()->getOwner()->getExtends(true)))) |
90 | ->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_USES, sprintf('%s::saveLastError()', $this->getMethod()->getOwner()->getExtends(true)))) |
91 | ; |
92 | |
93 | return $this; |
94 | } |
95 | |
96 | protected function addOperationMethodParam(PhpAnnotationBlock $annotationBlock): self |
97 | { |
98 | $this->addOperationMethodParamFromArray($annotationBlock)->addOperationMethodParamFromModel($annotationBlock)->addOperationMethodParamFromString($annotationBlock); |
99 | |
100 | return $this; |
101 | } |
102 | |
103 | protected function addOperationMethodParamFromArray(PhpAnnotationBlock $annotationBlock): self |
104 | { |
105 | if ($this->isParameterTypeAnArray()) { |
106 | foreach ($this->getParameterTypeArrayTypes() as $parameterName => $parameterType) { |
107 | $annotationBlock->addChild($this->getOperationMethodParam($parameterType, $this->getParameterName($parameterName))); |
108 | } |
109 | } |
110 | |
111 | return $this; |
112 | } |
113 | |
114 | protected function addOperationMethodParamFromModel(PhpAnnotationBlock $annotationBlock): self |
115 | { |
116 | if ($this->isParameterTypeAModel()) { |
117 | $annotationBlock->addChild($this->getOperationMethodParam($this->getParameterTypeModel()->getPackagedName(true), $this->getParameterName($this->getParameterTypeModel()->getPackagedName()))); |
118 | } |
119 | |
120 | return $this; |
121 | } |
122 | |
123 | protected function getOperationMethodParam(string $type, string $name): PhpAnnotation |
124 | { |
125 | return new PhpAnnotation(AbstractModelFile::ANNOTATION_PARAM, sprintf('%s $%s', $type, $name)); |
126 | } |
127 | |
128 | protected function addOperationMethodParamFromString(PhpAnnotationBlock $annotationBlock): self |
129 | { |
130 | if ($this->isParameterTypeAString() && !$this->isParameterTypeAModel()) { |
131 | $annotationBlock->addChild($this->getOperationMethodParam($this->getMethod()->getParameterType(), lcfirst($this->getMethod()->getParameterType()))); |
132 | } |
133 | |
134 | return $this; |
135 | } |
136 | |
137 | protected function addOperationMethodReturn(PhpAnnotationBlock $annotationBlock): self |
138 | { |
139 | $annotationBlock->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, sprintf('%s|bool', $this->getOperationMethodReturnType($this->getMethod())))); |
140 | |
141 | return $this; |
142 | } |
143 | |
144 | protected function getOperationMethodReturnType(MethodModel $method): string |
145 | { |
146 | return Service::getOperationMethodReturnType($method, $this->getGenerator()); |
147 | } |
148 | } |