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