TagHeader::getAttributePart()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\WsdlHandler\Tag;
6
7
use WsdlToPhp\DomHandler\AbstractAttributeHandler as Attribute;
8
use WsdlToPhp\WsdlHandler\AbstractDocument;
9
10
class TagHeader extends AbstractTagOperationElement
11
{
12
    public const ATTRIBUTE_PART = 'part';
13
    public const REQUIRED_HEADER = 'required';
14
    public const OPTIONAL_HEADER = 'optional';
15
    public const ATTRIBUTE_REQUIRED = 'wsdl:required';
16
17 2
    public function getParentInput(): ?TagInput
18
    {
19 2
        return $this->getStrictParent(AbstractDocument::TAG_INPUT);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getStrictP...actDocument::TAG_INPUT) returns the type WsdlToPhp\DomHandler\ElementHandler which includes types incompatible with the type-hinted return WsdlToPhp\WsdlHandler\Tag\TagInput|null.
Loading history...
20
    }
21
22 4
    public function getAttributeRequired(): bool
23
    {
24 4
        return $this->hasAttribute(self::ATTRIBUTE_REQUIRED) ? $this->getAttribute(self::ATTRIBUTE_REQUIRED)->getValue(true, true, 'bool') : true;
25
    }
26
27 2
    public function getAttributeNamespace(): string
28
    {
29 2
        return $this->hasAttribute(Attribute::ATTRIBUTE_NAMESPACE) ? $this->getAttribute(Attribute::ATTRIBUTE_NAMESPACE)->getValue() : '';
30
    }
31
32 16
    public function getAttributePart(): string
33
    {
34 16
        return $this->hasAttribute(self::ATTRIBUTE_PART) ? $this->getAttribute(self::ATTRIBUTE_PART)->getValue() : '';
35
    }
36
37 14
    public function getPartTag(): ?TagPart
38
    {
39 14
        return $this->getPart($this->getAttributePart());
40
    }
41
42 2
    public function getHeaderType(): string
43
    {
44 2
        $part = $this->getPartTag();
45
46 2
        return $part instanceof TagPart ? $part->getFinalType() : '';
47
    }
48
49 2
    public function getHeaderName(): string
50
    {
51 2
        $part = $this->getPartTag();
52
53 2
        return $part instanceof TagPart ? $part->getFinalName() : '';
54
    }
55
56 4
    public function getHeaderNamespace(): string
57
    {
58 4
        $namespace = $this->getHeaderNamespaceFromPart();
59 4
        if (empty($namespace)) {
60
            $namespace = $this->getHeaderNamespaceFromMessage();
61
        }
62
63 4
        return $namespace;
64
    }
65
66 2
    public function getHeaderRequired(): string
67
    {
68 2
        return $this->getAttributeRequired() ? self::REQUIRED_HEADER : self::OPTIONAL_HEADER;
69
    }
70
71 4
    protected function getHeaderNamespaceFromPart(): string
72
    {
73 4
        $part = $this->getPartTag();
74 4
        $namespace = '';
75 4
        if ($part instanceof TagPart) {
76 4
            $finalNamespace = $part->getFinalNamespace();
77 4
            if (!empty($finalNamespace)) {
78 2
                $namespace = $this->getDomDocumentHandler()->getNamespaceUri($finalNamespace);
79 2
            } elseif (($element = $part->getMatchingElement()) instanceof TagElement) {
80 2
                $namespace = $element->getTargetNamespace();
81
            }
82
        }
83
84 4
        return $namespace;
85
    }
86
87
    protected function getHeaderNamespaceFromMessage(): string
88
    {
89
        $namespace = '';
90
        $messageNamespace = $this->getAttributeMessageNamespace();
91
        if (!empty($messageNamespace)) {
92
            $namespace = $this->getDomDocumentHandler()->getNamespaceUri($messageNamespace);
93
        }
94
95
        return $namespace;
96
    }
97
}
98