Issues (17)

src/AbstractDocument.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\WsdlHandler;
6
7
use WsdlToPhp\DomHandler\AbstractDomDocumentHandler;
8
use WsdlToPhp\DomHandler\DomDocumentHandler;
9
use WsdlToPhp\DomHandler\ElementHandler;
10
use WsdlToPhp\WsdlHandler\Tag\Tag;
11
12
abstract class AbstractDocument extends DomDocumentHandler
13
{
14
    public const TAG_ADDRESS = 'address';
15
    public const TAG_ALL = 'all';
16
    public const TAG_ANNOTATION = 'annotation';
17
    public const TAG_ANY = 'any';
18
    public const TAG_ANY_ATTRIBUTE = 'anyAttribute';
19
    public const TAG_APPINFO = 'appinfo';
20
    public const TAG_ATTRIBUTE = 'attribute';
21
    public const TAG_ATTRIBUTE_GROUP = 'attributeGroup';
22
    public const TAG_BINDING = 'binding';
23
    public const TAG_BODY = 'body';
24
    public const TAG_CHOICE = 'choice';
25
    public const TAG_COMPLEX_CONTENT = 'complexContent';
26
    public const TAG_COMPLEX_TYPE = 'complexType';
27
    public const TAG_DEFINITIONS = 'definitions';
28
    public const TAG_DOCUMENTATION = 'documentation';
29
    public const TAG_ELEMENT = 'element';
30
    public const TAG_ENUMERATION = 'enumeration';
31
    public const TAG_EXTENSION = 'extension';
32
    public const TAG_FIELD = 'field';
33
    public const TAG_GROUP = 'group';
34
    public const TAG_HEADER = 'header';
35
    public const TAG_IMPORT = 'import';
36
    public const TAG_INCLUDE = 'include';
37
    public const TAG_INPUT = 'input';
38
    public const TAG_KEY = 'key';
39
    public const TAG_KEYREF = 'keyref';
40
    public const TAG_LIST = 'list';
41
    public const TAG_MEMBER_TYPES = 'memberTypes';
42
    public const TAG_MESSAGE = 'message';
43
    public const TAG_NOTATION = 'notation';
44
    public const TAG_OPERATION = 'operation';
45
    public const TAG_OUTPUT = 'output';
46
    public const TAG_PART = 'part';
47
    public const TAG_PORT = 'port';
48
    public const TAG_PORT_TYPE = 'portType';
49
    public const TAG_REDEFINE = 'redefine';
50
    public const TAG_RESTRICTION = 'restriction';
51
    public const TAG_SELECTOR = 'selector';
52
    public const TAG_SEQUENCE = 'sequence';
53
    public const TAG_SCHEMA = 'schema';
54
    public const TAG_SIMPLE_CONTENT = 'simpleContent';
55
    public const TAG_SIMPLE_TYPE = 'simpleType';
56
    public const TAG_TYPES = 'types';
57
    public const TAG_UNION = 'union';
58
    public const TAG_UNIQUE = 'unique';
59
60
    public const ATTRIBUTE_TARGET_NAMESPACE = 'targetNamespace';
61
62 4
    public function getNamespaceUri(string $namespace): string
63
    {
64 4
        $rootElement = $this->getRootElement();
65 4
        $uri = '';
66 4
        if ($rootElement instanceof ElementHandler && $rootElement->hasAttribute(sprintf('xmlns:%s', $namespace))) {
67 4
            $uri = $rootElement->getAttributeValue(sprintf('xmlns:%s', $namespace));
68
        }
69
70 4
        return $uri;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $uri could return the type boolean|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
71
    }
72
73 2
    public function getAttributeTargetNamespaceValue(): string
74
    {
75 2
        $namespace = '';
76 2
        $rootElement = $this->getRootElement();
77
78 2
        if ($rootElement instanceof ElementHandler && $rootElement->hasAttribute(self::ATTRIBUTE_TARGET_NAMESPACE)) {
79 2
            $namespace = $rootElement->getAttributeValue(self::ATTRIBUTE_TARGET_NAMESPACE, true);
80
        }
81
82 2
        return $namespace;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $namespace could return the type boolean|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
83
    }
84
85 136
    protected function getElementHandler(\DOMElement $element, AbstractDomDocumentHandler $domDocument, int $index = -1): ElementHandler
86
    {
87 136
        $handlerName = Tag::class;
88 136
        if (class_exists($elementNameClass = sprintf('%s\Tag\Tag%s', __NAMESPACE__, ucfirst(implode('', array_slice(explode(':', $element->nodeName), -1, 1)))))) {
89 136
            $handlerName = $elementNameClass;
90
        }
91
92 136
        return new $handlerName($element, $domDocument, $index);
93
    }
94
}
95