Passed
Push — master ( 54bedc...fe2750 )
by Tim
02:40
created

AbstractAdditionalContextType   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 24
dl 0
loc 88
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 17 4
A __construct() 0 7 1
A getContextItem() 0 3 1
A fromXML() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\auth;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\WSSecurity\XML\auth\ContextItem;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\ExtendableElementTrait;
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class defining the AdditionalContextType element
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractAdditionalContextType extends AbstractAuthElement
21
{
22
    use ExtendableAttributesTrait;
23
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...ctAdditionalContextType: $namespaceURI, $localName, $childNodes
Loading history...
24
25
    /** The namespace-attribute for the xs:anyAttribute */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
27
28
    /** The namespace-attribute for the xs:any */
29
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
30
31
32
    /**
33
     * AbstractAdditionalContextType constructor
34
     *
35
     * @param \SimpleSAML\WSSecurity\XML\auth\ContextItem[] $contextItem
36
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
37
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\auth\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
     */
39
    final public function __construct(
40
        protected array $contextItem = [],
41
        array $children = [],
42
        array $namespacedAttributes = [],
43
    ) {
44
        $this->setElements($children);
45
        $this->setAttributesNS($namespacedAttributes);
46
    }
47
48
49
    /**
50
     * Get the value of the $contextItem property.
51
     *
52
     * @return \SimpleSAML\WSSecurity\XML\auth\ContextItem[]
53
     */
54
    public function getContextItem(): array
55
    {
56
        return $this->contextItem;
57
    }
58
59
60
    /**
61
     * Create an instance of this object from its XML representation.
62
     *
63
     * @param \DOMElement $xml
64
     * @return static
65
     *
66
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
67
     *   if the qualified name of the supplied element is wrong
68
     */
69
    public static function fromXML(DOMElement $xml): static
70
    {
71
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
72
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
73
74
        $contextItem = ContextItem::getChildrenOfClass($xml);
75
        $children = self::getChildElementsFromXML($xml);
76
77
        return new static(
78
            $contextItem,
79
            $children,
80
            self::getAttributesNSFromXML($xml),
81
        );
82
    }
83
84
85
    /**
86
     * Add this AdditionalContext to an XML element.
87
     *
88
     * @param \DOMElement $parent The element we should append this username token to.
89
     * @return \DOMElement
90
     */
91
    public function toXML(DOMElement $parent = null): DOMElement
92
    {
93
        $e = $this->instantiateParentElement($parent);
94
95
        foreach ($this->getAttributesNS() as $attr) {
96
            $attr->toXML($e);
97
        }
98
99
        foreach ($this->getContextItem() as $ctx) {
100
            $ctx->toXML($e);
101
        }
102
103
        foreach ($this->getElements() as $elt) {
104
            $elt->toXML($e);
105
        }
106
107
        return $e;
108
    }
109
}
110