AbstractClaimTypesRequestedType::getClaimType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\WSSecurity\XML\auth\ClaimType;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
14
use SimpleSAML\XMLSchema\XML\Constants\NS;
15
16
/**
17
 * Class defining the ClaimTypesRequestedType element
18
 *
19
 * @package simplesamlphp/ws-security
20
 */
21
abstract class AbstractClaimTypesRequestedType extends AbstractFedElement
22
{
23
    use ExtendableAttributesTrait;
24
25
26
    /** The namespace-attribute for the xs:anyAttribute element */
27
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
28
29
30
    /**
31
     * AbstractClaimTypesRequestedType constructor
32
     *
33
     * @param \SimpleSAML\WSSecurity\XML\auth\ClaimType[] $claimType
34
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
35
     */
36
    final public function __construct(
37
        protected array $claimType,
38
        array $namespacedAttributes = [],
39
    ) {
40
        Assert::notEmpty($claimType, SchemaViolationException::class);
41
        Assert::allIsInstanceOf($claimType, ClaimType::class);
42
43
        $this->setAttributesNS($namespacedAttributes);
44
    }
45
46
47
    /**
48
     * @return \SimpleSAML\WSSecurity\XML\auth\ClaimType[]
49
     */
50
    public function getClaimType(): array
51
    {
52
        return $this->claimType;
53
    }
54
55
56
    /**
57
     * Create an instance of this object from its XML representation.
58
     *
59
     * @param \DOMElement $xml
60
     * @return static
61
     *
62
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
63
     *   if the qualified name of the supplied element is wrong
64
     */
65
    public static function fromXML(DOMElement $xml): static
66
    {
67
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
68
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
69
70
        $claimType = ClaimType::getChildrenOfClass($xml);
71
        Assert::minCount(
72
            $claimType,
73
            1,
74
            MissingElementException::class,
75
        );
76
77
        return new static(
78
            $claimType,
79
            self::getAttributesNSFromXML($xml),
80
        );
81
    }
82
83
84
    /**
85
     * Add this ClaimTypesRequestedType to an XML element.
86
     *
87
     * @param \DOMElement|null $parent The element we should append this ClaimTypesRequestedType to.
88
     * @return \DOMElement
89
     */
90
    public function toXML(?DOMElement $parent = null): DOMElement
91
    {
92
        $e = parent::instantiateParentElement($parent);
93
94
        foreach ($this->getAttributesNS() as $attr) {
95
            $attr->toXML($e);
96
        }
97
98
        foreach ($this->getClaimType() as $claimType) {
99
            $claimType->toXML($e);
100
        }
101
102
        return $e;
103
    }
104
}
105