Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| TagDocumentation | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
26 | |
100.00% |
1 / 1 |
| parseDocumentation | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
23 | |||
| parseWsdl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| parsingTag | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WsdlToPhp\PackageGenerator\Parser\Wsdl; |
| 6 | |
| 7 | use WsdlToPhp\PackageGenerator\Model\Struct; |
| 8 | use WsdlToPhp\PackageGenerator\Model\StructAttribute; |
| 9 | use WsdlToPhp\PackageGenerator\Model\StructValue; |
| 10 | use WsdlToPhp\PackageGenerator\Model\Wsdl; |
| 11 | use WsdlToPhp\WsdlHandler\Tag\Tag; |
| 12 | use WsdlToPhp\WsdlHandler\Tag\TagAttributeGroup; |
| 13 | use WsdlToPhp\WsdlHandler\Tag\TagDocumentation as Documentation; |
| 14 | use WsdlToPhp\WsdlHandler\Tag\TagEnumeration as Enumeration; |
| 15 | use WsdlToPhp\WsdlHandler\Wsdl as WsdlDocument; |
| 16 | |
| 17 | final class TagDocumentation extends AbstractTagParser |
| 18 | { |
| 19 | public function parseDocumentation(Documentation $documentation): void |
| 20 | { |
| 21 | $content = $documentation->getContent(); |
| 22 | $parent = $documentation->getSuitableParent(); |
| 23 | $parentParent = $parent instanceof Tag ? $parent->getSuitableParent() : null; |
| 24 | |
| 25 | if (empty($content) || !$parent instanceof Tag) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * Is it an element ? part of an attributeGroup |
| 31 | * Finds parent node of this documentation node |
| 32 | */ |
| 33 | if ($parent->hasAttribute('type') && $parentParent instanceof TagAttributeGroup) { |
| 34 | foreach ($parentParent->getReferencingElements() as $element) { |
| 35 | if (($model = $this->getModel($element)) instanceof Struct && ($attribute = $model->getAttribute($parent->getAttributeName())) instanceof StructAttribute) { |
| 36 | $attribute->setDocumentation($content); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | /* |
| 41 | * Is it an element ? part of a struct |
| 42 | * Finds parent node of this documentation node |
| 43 | */ |
| 44 | elseif ($parent->hasAttribute('type') && $parentParent instanceof Tag) { |
| 45 | if (($model = $this->getModel($parentParent)) instanceof Struct && ($attribute = $model->getAttribute($parent->getAttributeName())) instanceof StructAttribute) { |
| 46 | $attribute->setDocumentation($content); |
| 47 | } |
| 48 | } |
| 49 | /* |
| 50 | * Is it a value of an enumeration ? |
| 51 | * Finds parent node of this documentation node |
| 52 | */ |
| 53 | elseif ($parent instanceof Enumeration && $parentParent instanceof Tag) { |
| 54 | if (($model = $this->getModel($parentParent)) instanceof Struct && ($structValue = $model->getValue($parent->getValue())) instanceof StructValue) { |
| 55 | $structValue->setDocumentation($content); |
| 56 | } |
| 57 | } |
| 58 | // Is it a restriction with enumeration (a real struct) that needs to find the model based on its type ? |
| 59 | elseif ($parent->hasRestrictionChild() && $parent->getFirstRestrictionChild()->isEnumeration() && $parent->getFirstRestrictionChild()->isTheParent($parent)) { |
| 60 | $model = $this->getModel($parent, $parent->getFirstRestrictionChild()->getAttributeBase()); |
| 61 | $model = $model ? $model : $this->getModel($parent); |
| 62 | if ($model instanceof Struct) { |
| 63 | $model->setDocumentation($content); |
| 64 | } |
| 65 | } |
| 66 | /* |
| 67 | * Is it an element ? |
| 68 | * Finds parent node of this documentation node |
| 69 | */ |
| 70 | elseif ($model = $this->getModel($parent)) { |
| 71 | $model->setDocumentation($content); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | protected function parseWsdl(Wsdl $wsdl): void |
| 76 | { |
| 77 | foreach ($this->getTags() as $tag) { |
| 78 | $this->parseDocumentation($tag); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | protected function parsingTag(): string |
| 83 | { |
| 84 | return WsdlDocument::TAG_DOCUMENTATION; |
| 85 | } |
| 86 | } |