Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
AbstractParser | |
100.00% |
30 / 30 |
|
100.00% |
7 / 7 |
16 | |
100.00% |
1 / 1 |
parse | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
4 | |||
getTags | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isWsdlParsed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |||
isSchemaParsed | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
parseWsdl | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
parseSchema | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
parsingTag | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
setTags | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setWsdlAsParsed | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
setSchemaAsParsed | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace WsdlToPhp\PackageGenerator\Parser\Wsdl; |
6 | |
7 | use WsdlToPhp\PackageGenerator\Model\Schema; |
8 | use WsdlToPhp\PackageGenerator\Model\Wsdl; |
9 | use WsdlToPhp\PackageGenerator\Parser\AbstractParser as Parser; |
10 | use WsdlToPhp\WsdlHandler\Tag\AbstractTag; |
11 | |
12 | abstract class AbstractParser extends Parser |
13 | { |
14 | /** |
15 | * @var AbstractTag[] |
16 | */ |
17 | protected array $tags; |
18 | |
19 | /** |
20 | * List of Wsdl parsed for the current tag. |
21 | */ |
22 | protected array $parsedWsdls = []; |
23 | |
24 | /** |
25 | * List of Schema parsed for the current tag. |
26 | */ |
27 | protected array $parsedSchemas = []; |
28 | |
29 | /** |
30 | * The method takes care of looping among WSDLS as much time as it is needed. |
31 | */ |
32 | final public function parse(): void |
33 | { |
34 | $wsdl = $this->generator->getWsdl(); |
35 | |
36 | if (!$this->isWsdlParsed($wsdl)) { |
37 | $this |
38 | ->setWsdlAsParsed($wsdl) |
39 | ->setTags($wsdl->getContent()->getElementsByName($this->parsingTag())) |
40 | ->parseWsdl($wsdl) |
41 | ; |
42 | } |
43 | |
44 | /** @var Schema $schema */ |
45 | foreach ($wsdl->getSchemas() as $schema) { |
46 | if ($this->isSchemaParsed($wsdl, $schema)) { |
47 | continue; |
48 | } |
49 | |
50 | $this->setSchemaAsParsed($wsdl, $schema); |
51 | |
52 | $this |
53 | ->setTags($schema->getContent()->getElementsByName($this->parsingTag())) |
54 | ->parseSchema($wsdl, $schema) |
55 | ; |
56 | } |
57 | } |
58 | |
59 | public function getTags(): array |
60 | { |
61 | return $this->tags; |
62 | } |
63 | |
64 | public function isWsdlParsed(Wsdl $wsdl): bool |
65 | { |
66 | return array_key_exists($wsdl->getName(), $this->parsedWsdls) && is_array($this->parsedWsdls[$wsdl->getName()]) && in_array($this->parsingTag(), $this->parsedWsdls[$wsdl->getName()]); |
67 | } |
68 | |
69 | public function isSchemaParsed(Wsdl $wsdl, Schema $schema): bool |
70 | { |
71 | $key = $wsdl->getName().$schema->getName(); |
72 | |
73 | return array_key_exists($key, $this->parsedSchemas) && is_array($this->parsedSchemas[$key]) && in_array($this->parsingTag(), $this->parsedSchemas[$key]); |
74 | } |
75 | |
76 | abstract protected function parseWsdl(Wsdl $wsdl): void; |
77 | |
78 | abstract protected function parseSchema(Wsdl $wsdl, Schema $schema): void; |
79 | |
80 | abstract protected function parsingTag(): string; |
81 | |
82 | protected function setTags(array $tags): self |
83 | { |
84 | $this->tags = $tags; |
85 | |
86 | return $this; |
87 | } |
88 | |
89 | protected function setWsdlAsParsed(Wsdl $wsdl): self |
90 | { |
91 | if (!array_key_exists($wsdl->getName(), $this->parsedWsdls)) { |
92 | $this->parsedWsdls[$wsdl->getName()] = []; |
93 | } |
94 | $this->parsedWsdls[$wsdl->getName()][] = $this->parsingTag(); |
95 | |
96 | return $this; |
97 | } |
98 | |
99 | protected function setSchemaAsParsed(Wsdl $wsdl, Schema $schema): self |
100 | { |
101 | $key = $wsdl->getName().$schema->getName(); |
102 | if (!array_key_exists($key, $this->parsedSchemas)) { |
103 | $this->parsedSchemas[$key] = []; |
104 | } |
105 | $this->parsedSchemas[$key][] = $this->parsingTag(); |
106 | |
107 | return $this; |
108 | } |
109 | } |