AbstractFederationType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\fed;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\SchemaViolationException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\ExtendableElementTrait;
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class defining the FederationType element
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractFederationType extends AbstractFedElement
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...\AbstractFederationType: $namespaceURI, $localName, $childNodes
Loading history...
24
25
    /** The namespace-attribute for the xs:anyAttribute element */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
27
28
    /** The namespace-attribute for the xs:any element */
29
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
30
31
32
    /**
33
     * AbstractFederationType constructor
34
     *
35
     * @param string|null $FederationID
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\fed\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 ?string $FederationID = null,
41
        array $children = [],
42
        array $namespacedAttributes = [],
43
    ) {
44
        Assert::nullOrValidURI($FederationID, SchemaViolationException::class);
45
46
        $this->setElements($children);
47
        $this->setAttributesNS($namespacedAttributes);
48
    }
49
50
51
    /**
52
     * @return string|null
53
     */
54
    public function getFederationID(): ?string
55
    {
56
        return $this->FederationID;
57
    }
58
59
60
    /**
61
     * Test if an object, at the state it's in, would produce an empty XML-element
62
     *
63
     * @return bool
64
     */
65
    public function isEmptyElement(): bool
66
    {
67
        return empty($this->getFederationID())
68
            && empty($this->getElements())
69
            && empty($this->getAttributesNS());
70
    }
71
72
73
    /**
74
     * Create an instance of this object from its XML representation.
75
     *
76
     * @param \DOMElement $xml
77
     * @return static
78
     *
79
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
80
     *   if the qualified name of the supplied element is wrong
81
     */
82
    public static function fromXML(DOMElement $xml): static
83
    {
84
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
85
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
86
87
        return new static(
88
            self::getOptionalAttribute($xml, 'FederationID', null),
89
            self::getChildElementsFromXML($xml),
90
            self::getAttributesNSFromXML($xml),
91
        );
92
    }
93
94
95
    /**
96
     * Add this FederationType to an XML element.
97
     *
98
     * @param \DOMElement|null $parent The element we should append this FederationType to.
99
     * @return \DOMElement
100
     */
101
    public function toXML(?DOMElement $parent = null): DOMElement
102
    {
103
        $e = parent::instantiateParentElement($parent);
104
105
        if ($this->getFederationID() !== null) {
106
            $e->setAttribute('FederationID', $this->getFederationID());
107
        }
108
109
        foreach ($this->getAttributesNS() as $attr) {
110
            $attr->toXML($e);
111
        }
112
113
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
114
        foreach ($this->getElements() as $child) {
115
            if (!$child->isEmptyElement()) {
116
                $child->toXML($e);
117
            }
118
        }
119
120
        return $e;
121
    }
122
}
123