AbstractRequestSecurityTokenResponseCollectionType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 21
c 1
b 0
f 0
dl 0
loc 79
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequestSecurityTokenResponse() 0 3 1
A fromXML() 0 8 1
A toXML() 0 13 3
A __construct() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wst_200502;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Exception\MissingElementException;
12
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
13
use SimpleSAML\XMLSchema\XML\Constants\NS;
14
15
/**
16
 * A RequestSecurityTokenResponseCollectionType element
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractRequestSecurityTokenResponseCollectionType extends AbstractWstElement
21
{
22
    use ExtendableAttributesTrait;
23
24
25
    /** @var string|\SimpleSAML\XML\XsNamespace */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
27
28
29
    /**
30
     * @param array<\SimpleSAML\WSSecurity\XML\wst_200502\RequestSecurityTokenResponse> $requestSecurityTokenResponse
31
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
32
     */
33
    final public function __construct(
34
        protected array $requestSecurityTokenResponse,
35
        array $namespacedAttributes,
36
    ) {
37
        Assert::minCount($requestSecurityTokenResponse, 1, MissingElementException::class);
38
        Assert::allIsInstanceOf(
39
            $requestSecurityTokenResponse,
40
            RequestSecurityTokenResponse::class,
41
            SchemaViolationException::class,
42
        );
43
44
        $this->setAttributesNS($namespacedAttributes);
45
    }
46
47
48
    /**
49
     * Get the requestSecurityTokenResponse property.
50
     *
51
     * @return \SimpleSAML\WSSecurity\XML\wst_200502\RequestSecurityTokenResponse[]
52
     */
53
    public function getRequestSecurityTokenResponse(): array
54
    {
55
        return $this->requestSecurityTokenResponse;
56
    }
57
58
59
    /**
60
     * Convert XML into a class instance
61
     *
62
     * @param \DOMElement $xml The XML element we should load
63
     * @return static
64
     *
65
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
66
     *   If the qualified name of the supplied element is wrong
67
     */
68
    public static function fromXML(DOMElement $xml): static
69
    {
70
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
71
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
72
73
        return new static(
74
            RequestSecurityTokenResponse::getChildrenOfClass($xml),
75
            self::getAttributesNSFromXML($xml),
76
        );
77
    }
78
79
80
    /**
81
     * Convert this element to XML.
82
     *
83
     * @param \DOMElement|null $parent The element we should append this element to.
84
     * @return \DOMElement
85
     */
86
    public function toXML(?DOMElement $parent = null): DOMElement
87
    {
88
        $e = $this->instantiateParentElement($parent);
89
90
        foreach ($this->getRequestSecurityTokenResponse() as $r) {
91
            $r->toXML($e);
92
        }
93
94
        foreach ($this->getAttributesNS() as $attr) {
95
            $attr->toXML($e);
96
        }
97
98
        return $e;
99
    }
100
}
101