Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.94% |
31 / 33 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
AbstractTagInputOutputParser | |
93.94% |
31 / 33 |
|
75.00% |
3 / 4 |
21.10 | |
0.00% |
0 / 1 |
parseInputOutput | |
90.91% |
20 / 22 |
|
0.00% |
0 / 1 |
13.13 | |||
getKnownType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
setKnownType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
parseWsdl | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getTypeFromPart | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isKnownTypeUnknown | |
100.00% |
8 / 8 |
|
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\Method; |
8 | use WsdlToPhp\PackageGenerator\Model\Wsdl; |
9 | use WsdlToPhp\WsdlHandler\Tag\AbstractTagOperationElement; |
10 | use WsdlToPhp\WsdlHandler\Tag\TagOperation; |
11 | use WsdlToPhp\WsdlHandler\Tag\TagPart; |
12 | |
13 | abstract class AbstractTagInputOutputParser extends AbstractTagParser |
14 | { |
15 | public const UNKNOWN = 'unknown'; |
16 | |
17 | public function parseInputOutput(AbstractTagOperationElement $tag): void |
18 | { |
19 | if (!$tag->hasAttributeMessage()) { |
20 | return; |
21 | } |
22 | |
23 | $operation = $tag->getParentOperation(); |
24 | if (!$operation instanceof TagOperation) { |
25 | return; |
26 | } |
27 | |
28 | $method = $this->getModel($operation); |
29 | if (!$method instanceof Method) { |
30 | return; |
31 | } |
32 | |
33 | if (!$this->isKnownTypeUnknown($method)) { |
34 | return; |
35 | } |
36 | |
37 | $parts = $tag->getParts(); |
38 | $multipleParts = count($parts); |
39 | if (is_array($parts) && $multipleParts > 1) { |
40 | $types = []; |
41 | foreach ($parts as $part) { |
42 | if (!empty($type = $this->getTypeFromPart($part))) { |
43 | $types[$part->getAttributeName()] = $type; |
44 | } |
45 | } |
46 | $this->setKnownType($method, $types); |
47 | } elseif (is_array($parts) && $multipleParts > 0) { |
48 | $part = array_shift($parts); |
49 | if ($part instanceof TagPart && !empty($type = $this->getTypeFromPart($part))) { |
50 | $this->setKnownType($method, $type); |
51 | } |
52 | } |
53 | } |
54 | |
55 | abstract protected function getKnownType(Method $method); |
56 | |
57 | abstract protected function setKnownType(Method $method, $knownType); |
58 | |
59 | protected function parseWsdl(Wsdl $wsdl): void |
60 | { |
61 | foreach ($this->getTags() as $tag) { |
62 | $this->parseInputOutput($tag); |
63 | } |
64 | } |
65 | |
66 | protected function getTypeFromPart(TagPart $part): string |
67 | { |
68 | return $part->getFinalType(); |
69 | } |
70 | |
71 | protected function isKnownTypeUnknown(Method $method): bool |
72 | { |
73 | $isKnown = true; |
74 | $knownType = $this->getKnownType($method); |
75 | if (is_string($knownType)) { |
76 | $isKnown = !empty($knownType) && self::UNKNOWN !== mb_strtolower($knownType); |
77 | } elseif (is_array($knownType)) { |
78 | foreach ($knownType as $knownValue) { |
79 | $isKnown &= self::UNKNOWN !== mb_strtolower($knownValue); |
80 | } |
81 | } |
82 | |
83 | return (bool) !$isKnown; |
84 | } |
85 | } |