AbstractLogicalServiceNamesOfferedType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIssuerName() 0 3 1
A fromXML() 0 16 1
A __construct() 0 8 1
A toXML() 0 13 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\WSSecurity\XML\fed\IssuerName;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\MissingElementException;
12
use SimpleSAML\XML\Exception\SchemaViolationException;
13
use SimpleSAML\XML\ExtendableAttributesTrait;
14
use SimpleSAML\XML\XsNamespace as NS;
15
16
/**
17
 * Class defining the LogicalServiceNamesOfferedType element
18
 *
19
 * @package simplesamlphp/ws-security
20
 */
21
abstract class AbstractLogicalServiceNamesOfferedType extends AbstractFedElement
22
{
23
    use ExtendableAttributesTrait;
24
25
    /** The namespace-attribute for the xs:anyAttribute element */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
27
28
29
    /**
30
     * LogicalServiceNamesOfferedType constructor
31
     *
32
     * @param array<\SimpleSAML\WSSecurity\XML\fed\IssuerName> $issuerName
33
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
34
     */
35
    final public function __construct(
36
        protected array $issuerName,
37
        array $namespacedAttributes = [],
38
    ) {
39
        Assert::notEmpty($issuerName, SchemaViolationException::class);
40
        Assert::allIsInstanceOf($issuerName, IssuerName::class);
41
42
        $this->setAttributesNS($namespacedAttributes);
43
    }
44
45
46
    /**
47
     * @return array<\SimpleSAML\WSSecurity\XML\fed\IssuerName>
48
     */
49
    public function getIssuerName(): array
50
    {
51
        return $this->issuerName;
52
    }
53
54
55
    /**
56
     * Create an instance of this object from its XML representation.
57
     *
58
     * @param \DOMElement $xml
59
     * @return static
60
     *
61
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
62
     *   if the qualified name of the supplied element is wrong
63
     */
64
    public static function fromXML(DOMElement $xml): static
65
    {
66
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
67
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
68
69
        $issuerName = IssuerName::getChildrenOfClass($xml);
70
        Assert::minCount(
71
            $issuerName,
72
            1,
73
            'Missing <fed:IssuerName> in LogicalServiceNamesOfferedType.',
74
            MissingElementException::class,
75
        );
76
77
        return new static(
78
            $issuerName,
79
            self::getAttributesNSFromXML($xml),
80
        );
81
    }
82
83
84
    /**
85
     * Add this LogicalServiceNamesOfferedType to an XML element.
86
     *
87
     * @param \DOMElement|null $parent The element we should append this LogicalServiceNamesOfferedType 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->getIssuerName() as $issuerName) {
99
            $issuerName->toXML($e);
100
        }
101
102
        return $e;
103
    }
104
}
105