Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
26 / 28 |
|
80.00% |
8 / 10 |
CRAP | |
0.00% |
0 / 1 |
| ClassMap | |
92.86% |
26 / 28 |
|
80.00% |
8 / 10 |
15.08 | |
0.00% |
0 / 1 |
| fillClassConstants | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getConstantAnnotationBlock | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fillClassProperties | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPropertyAnnotationBlock | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fillClassMethods | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getMethodAnnotationBlock | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getClassAnnotationBlock | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| addMethodBody | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| addStructToClassMapList | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| getStructName | |
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\Container\PhpElement\Constant as ConstantContainer; |
| 8 | use WsdlToPhp\PackageGenerator\Container\PhpElement\Property as PropertyContainer; |
| 9 | use WsdlToPhp\PackageGenerator\Model\Struct as StructModel; |
| 10 | use WsdlToPhp\PhpGenerator\Element\PhpAnnotation; |
| 11 | use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock; |
| 12 | use WsdlToPhp\PhpGenerator\Element\PhpConstant; |
| 13 | use WsdlToPhp\PhpGenerator\Element\PhpMethod; |
| 14 | use WsdlToPhp\PhpGenerator\Element\PhpProperty; |
| 15 | |
| 16 | final class ClassMap extends AbstractModelFile |
| 17 | { |
| 18 | public const METHOD_NAME = 'get'; |
| 19 | |
| 20 | protected function fillClassConstants(ConstantContainer $constants): void |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | protected function getConstantAnnotationBlock(PhpConstant $constant): ?PhpAnnotationBlock |
| 25 | { |
| 26 | return null; |
| 27 | } |
| 28 | |
| 29 | protected function fillClassProperties(PropertyContainer $properties): void |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | protected function getPropertyAnnotationBlock(PhpProperty $property): ?PhpAnnotationBlock |
| 34 | { |
| 35 | return null; |
| 36 | } |
| 37 | |
| 38 | protected function fillClassMethods(): void |
| 39 | { |
| 40 | $method = new PhpMethod(self::METHOD_NAME, [], self::TYPE_ARRAY, PhpMethod::ACCESS_PUBLIC, false, true, true); |
| 41 | $this->addMethodBody($method); |
| 42 | $this->methods->add($method); |
| 43 | } |
| 44 | |
| 45 | protected function getMethodAnnotationBlock(PhpMethod $method): ?PhpAnnotationBlock |
| 46 | { |
| 47 | return new PhpAnnotationBlock([ |
| 48 | 'Returns the mapping between the WSDL Structs and generated Structs\' classes', |
| 49 | 'This array is sent to the \SoapClient when calling the WS', |
| 50 | new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'), |
| 51 | ]); |
| 52 | } |
| 53 | |
| 54 | protected function getClassAnnotationBlock(): PhpAnnotationBlock |
| 55 | { |
| 56 | $annotations = [ |
| 57 | 'Class which returns the class map definition', |
| 58 | ]; |
| 59 | |
| 60 | if (!empty($this->getGenerator()->getOptionPrefix())) { |
| 61 | $annotations[] = new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix()); |
| 62 | } |
| 63 | |
| 64 | return new PhpAnnotationBlock($annotations); |
| 65 | } |
| 66 | |
| 67 | protected function addMethodBody(PhpMethod $method): self |
| 68 | { |
| 69 | if ($this->getGenerator()->getStructs()->count() > 0) { |
| 70 | $method->addChild('return ['); |
| 71 | foreach ($this->getGenerator()->getStructs() as $struct) { |
| 72 | $this->addStructToClassMapList($method, $struct); |
| 73 | } |
| 74 | $method->addChild('];'); |
| 75 | } |
| 76 | |
| 77 | return $this; |
| 78 | } |
| 79 | |
| 80 | protected function addStructToClassMapList(PhpMethod $method, StructModel $struct): self |
| 81 | { |
| 82 | if ($struct->isStruct() && !$struct->isRestriction()) { |
| 83 | $method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1)); |
| 84 | } |
| 85 | |
| 86 | return $this; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Work around for https://bugs.php.net/bug.php?id=69280. |
| 91 | */ |
| 92 | protected function getStructName(StructModel $struct): string |
| 93 | { |
| 94 | return str_replace('\\', '\\\\', $struct->getPackagedName(true)); |
| 95 | } |
| 96 | } |