Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractTagImportParser
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
4 / 4
9
100.00% covered (success)
100.00%
1 / 1
 parseWsdl
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 getLocation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parseSchema
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getTagParser
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace WsdlToPhp\PackageGenerator\Parser\Wsdl;
6
7use WsdlToPhp\PackageGenerator\Generator\Utils;
8use WsdlToPhp\PackageGenerator\Model\Schema;
9use WsdlToPhp\PackageGenerator\Model\Wsdl;
10use WsdlToPhp\WsdlHandler\AbstractDocument;
11
12abstract class AbstractTagImportParser extends AbstractTagParser
13{
14    protected function parseWsdl(Wsdl $wsdl, Schema $schema = null): void
15    {
16        foreach ($this->getTags() as $tag) {
17            if (empty($location = $tag->getLocationAttributeValue())) {
18                continue;
19            }
20
21            $finalLocation = Utils::resolveCompletePath($this->getLocation($wsdl, $schema), $location);
22            $this->generator->addSchemaToWsdl($wsdl, $finalLocation);
23        }
24    }
25
26    protected function getLocation(Wsdl $wsdl, Schema $schema = null): string
27    {
28        return ($schema ?? $wsdl)->getName();
29    }
30
31    /**
32     * The goal of this method is to ensure that each schema is parsed by both TagInclude and TagImport in case of one of the two does not find tags that matches its tag name.
33     * As the GeneratorParsers loads the include/import tags parses in a certain order, it can occur that import tags might be found after the import tag parser has been launched and vice versa.
34     */
35    protected function parseSchema(Wsdl $wsdl, Schema $schema): void
36    {
37        if (0 < count($this->getTags())) {
38            $this->parseWsdl($wsdl, $schema);
39        } else {
40            $this->getTagParser()->parse();
41        }
42    }
43
44    protected function getTagParser(): ?AbstractTagImportParser
45    {
46        $tagName = null;
47
48        switch ($this->parsingTag()) {
49            case AbstractDocument::TAG_IMPORT:
50                $tagName = AbstractDocument::TAG_INCLUDE;
51
52                break;
53
54            case AbstractDocument::TAG_INCLUDE:
55                $tagName = AbstractDocument::TAG_IMPORT;
56
57                break;
58        }
59
60        return $this->getGenerator()->getParsers()->getParsers()->getParserByName($tagName);
61    }
62}