Passed
Push — develop ( 3db47d...4127cf )
by Mikaël
02:22
created

AbstractDocument::getElementHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\WsdlHandler;
6
7
use DOMElement;
8
use WsdlToPhp\DomHandler\AbstractDomDocumentHandler;
9
use WsdlToPhp\DomHandler\DomDocumentHandler;
10
use WsdlToPhp\DomHandler\ElementHandler;
11
use WsdlToPhp\WsdlHandler\Tag\Tag;
12
13
abstract class AbstractDocument extends DomDocumentHandler
14
{
15
    const TAG_ADDRESS = 'address';
16
    const TAG_ALL = 'all';
17
    const TAG_ANNOTATION = 'annotation';
18
    const TAG_ANY = 'any';
19
    const TAG_ANY_ATTRIBUTE = 'anyAttribute';
20
    const TAG_APPINFO = 'appinfo';
21
    const TAG_ATTRIBUTE = 'attribute';
22
    const TAG_ATTRIBUTE_GROUP = 'attributeGroup';
23
    const TAG_BINDING = 'binding';
24
    const TAG_BODY = 'body';
25
    const TAG_CHOICE = 'choice';
26
    const TAG_COMPLEX_CONTENT = 'complexContent';
27
    const TAG_COMPLEX_TYPE = 'complexType';
28
    const TAG_DEFINITIONS = 'definitions';
29
    const TAG_DOCUMENTATION = 'documentation';
30
    const TAG_ELEMENT = 'element';
31
    const TAG_ENUMERATION = 'enumeration';
32
    const TAG_EXTENSION = 'extension';
33
    const TAG_FIELD = 'field';
34
    const TAG_GROUP = 'group';
35
    const TAG_HEADER = 'header';
36
    const TAG_IMPORT = 'import';
37
    const TAG_INCLUDE = 'include';
38
    const TAG_INPUT = 'input';
39
    const TAG_KEY = 'key';
40
    const TAG_KEYREF = 'keyref';
41
    const TAG_LIST = 'list';
42
    const TAG_MEMBER_TYPES = 'memberTypes';
43
    const TAG_MESSAGE = 'message';
44
    const TAG_NOTATION = 'notation';
45
    const TAG_OPERATION = 'operation';
46
    const TAG_OUTPUT = 'output';
47
    const TAG_PART = 'part';
48
    const TAG_PORT = 'port';
49
    const TAG_PORT_TYPE = 'portType';
50
    const TAG_REDEFINE = 'redefine';
51
    const TAG_RESTRICTION = 'restriction';
52
    const TAG_SELECTOR = 'selector';
53
    const TAG_SEQUENCE = 'sequence';
54
    const TAG_SCHEMA = 'schema';
55
    const TAG_SIMPLE_CONTENT = 'simpleContent';
56
    const TAG_SIMPLE_TYPE = 'simpleType';
57
    const TAG_TYPES = 'types';
58
    const TAG_UNION = 'union';
59
    const TAG_UNIQUE = 'unique';
60
61
    public function getNamespaceUri(string $namespace): string
62
    {
63
        $rootElement = $this->getRootElement();
64
        $uri = '';
65
        if ($rootElement instanceof ElementHandler && $rootElement->hasAttribute(sprintf('xmlns:%s', $namespace))) {
66
            $uri = $rootElement->getAttribute(sprintf('xmlns:%s', $namespace))->getValue();
67
        }
68
69
        return $uri;
70
    }
71
72
    protected function getElementHandler(DOMElement $element, AbstractDomDocumentHandler $domDocument, int $index = -1): ElementHandler
73
    {
74
        $handlerName = Tag::class;
75
        if (class_exists($elementNameClass = sprintf('%s\Tag\Tag%s', __NAMESPACE__, ucfirst(implode('', array_slice(explode(':', $element->nodeName), -1, 1)))))) {
76
            $handlerName = $elementNameClass;
77
        }
78
79
        return new $handlerName($element, $domDocument, $index);
80
    }
81
}
82