Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
84.85% |
28 / 33 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
TagUnion | |
84.85% |
28 / 33 |
|
60.00% |
3 / 5 |
19.13 | |
0.00% |
0 / 1 |
parseUnion | |
81.25% |
13 / 16 |
|
0.00% |
0 / 1 |
5.16 | |||
parseWsdl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
parsingTag | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
findSuitableInheritance | |
77.78% |
7 / 9 |
|
0.00% |
0 / 1 |
5.27 | |||
getUnionMemberTypesFromChildren | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace WsdlToPhp\PackageGenerator\Parser\Wsdl; |
6 | |
7 | use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
8 | use WsdlToPhp\PackageGenerator\Model\Wsdl; |
9 | use WsdlToPhp\WsdlHandler\Tag\TagSimpleType as SimpleType; |
10 | use WsdlToPhp\WsdlHandler\Tag\TagUnion as Union; |
11 | use WsdlToPhp\WsdlHandler\Wsdl as WsdlDocument; |
12 | |
13 | final class TagUnion extends AbstractTagParser |
14 | { |
15 | public function parseUnion(Union $union): void |
16 | { |
17 | $parent = $union->getSuitableParent(); |
18 | if (!$parent) { |
19 | return; |
20 | } |
21 | |
22 | $model = $this->getModel($parent); |
23 | if (!$model) { |
24 | return; |
25 | } |
26 | |
27 | $memberTypes = $union->getAttributeMemberTypes(); |
28 | if ($union->hasMemberTypesAsChildren()) { |
29 | $memberTypes = array_unique(array_merge($memberTypes, $this->getUnionMemberTypesFromChildren($union))); |
30 | } |
31 | |
32 | $memberTypes = array_filter($memberTypes, function ($memberType) use ($model) { |
33 | return $model->getName() !== $memberType; |
34 | }); |
35 | |
36 | if (empty($memberTypes)) { |
37 | return; |
38 | } |
39 | |
40 | $model->addMeta('union', $memberTypes); |
41 | $model->setInheritance($this->findSuitableInheritance($memberTypes)); |
42 | } |
43 | |
44 | protected function parseWsdl(Wsdl $wsdl): void |
45 | { |
46 | foreach ($this->getTags() as $tag) { |
47 | $this->parseUnion($tag); |
48 | } |
49 | } |
50 | |
51 | protected function parsingTag(): string |
52 | { |
53 | return WsdlDocument::TAG_UNION; |
54 | } |
55 | |
56 | protected function findSuitableInheritance(array $values): string |
57 | { |
58 | $validInheritance = ''; |
59 | foreach ($values as $value) { |
60 | $model = $this->getStructByName($value); |
61 | while ($model instanceof AbstractModel && !empty($model->getInheritance())) { |
62 | $model = $this->getStructByName($validInheritance = $model->getInheritance()); |
63 | } |
64 | |
65 | if ($model instanceof AbstractModel) { |
66 | $validInheritance = $model->getName(); |
67 | |
68 | break; |
69 | } |
70 | } |
71 | |
72 | return $validInheritance; |
73 | } |
74 | |
75 | protected function getUnionMemberTypesFromChildren(Union $union): array |
76 | { |
77 | $memberTypes = []; |
78 | foreach ($union->getMemberTypesChildren() as $child) { |
79 | if ($child instanceof SimpleType && $child->hasRestrictionChild() && '' !== $child->getFirstRestrictionChild()->getAttributeBase()) { |
80 | $memberTypes[] = $child->getFirstRestrictionChild()->getAttributeBase(); |
81 | } |
82 | } |
83 | |
84 | return array_unique($memberTypes); |
85 | } |
86 | } |