AbstractIssuedTokenType::getIssuer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\sp_200702;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XML\ExtendableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14
use SimpleSAML\XMLSchema\XML\Constants\NS;
15
16
use function array_pop;
17
use function sprintf;
18
19
/**
20
 * Class representing WS security policy IssuedTokenType.
21
 *
22
 * @package simplesamlphp/ws-security
23
 */
24
abstract class AbstractIssuedTokenType extends AbstractSpElement
25
{
26
    use ExtendableAttributesTrait;
27
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...AbstractIssuedTokenType: $namespaceURI, $localName, $childNodes
Loading history...
28
29
30
    /** The namespace-attribute for the xs:any element */
31
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
32
33
    /** The namespace-attribute for the xs:anyAttribute element */
34
    public const XS_ANY_ATTR_NAMESPACE = NS::ANY;
35
36
37
    /**
38
     * IssuedTokenType constructor.
39
     *
40
     * @param \SimpleSAML\WSSecurity\XML\sp_200702\RequestSecurityTokenTemplate $requestSecurityTokenTemplate
41
     * @param \SimpleSAML\WSSecurity\XML\sp_200702\Issuer|\SimpleSAML\WSSecurity\XML\sp_200702\IssuerName|null $issuer
42
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $elts
43
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\sp_200702\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...
44
     */
45
    final public function __construct(
46
        protected RequestSecurityTokenTemplate $requestSecurityTokenTemplate,
47
        protected Issuer|IssuerName|null $issuer = null,
48
        array $elts = [],
49
        array $namespacedAttributes = [],
50
    ) {
51
        $this->setElements($elts);
52
        $this->setAttributesNS($namespacedAttributes);
53
    }
54
55
56
    /**
57
     * Collect the value of the Issuer property.
58
     *
59
     * @return \SimpleSAML\WSSecurity\XML\sp_200702\Issuer|\SimpleSAML\WSSecurity\XML\sp_200702\IssuerName|null
60
     */
61
    public function getIssuer(): Issuer|IssuerName|null
62
    {
63
        return $this->issuer;
64
    }
65
66
67
    /**
68
     * Collect the value of the RequestSecurityTokenTemplate property.
69
     *
70
     * @return \SimpleSAML\WSSecurity\XML\sp_200702\RequestSecurityTokenTemplate
71
     */
72
    public function getRequestSecurityTokenTemplate(): RequestSecurityTokenTemplate
73
    {
74
        return $this->requestSecurityTokenTemplate;
75
    }
76
77
78
    /**
79
     * Initialize an IssuedTokenType.
80
     *
81
     * Note: this method cannot be used when extending this class, if the constructor has a different signature.
82
     *
83
     * @param \DOMElement $xml The XML element we should load.
84
     * @return static
85
     *
86
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
87
     *   if the qualified name of the supplied element is wrong
88
     */
89
    public static function fromXML(DOMElement $xml): static
90
    {
91
        $qualifiedName = static::getClassName(static::class);
92
        Assert::eq(
93
            $xml->localName,
94
            $qualifiedName,
95
            sprintf('Unexpected name for IssuedTokenType: %s. Expected: %s.', $xml->localName, $qualifiedName),
96
            InvalidDOMElementException::class,
97
        );
98
99
        $issuer = Issuer::getChildrenOfClass($xml);
100
        $issuerName = IssuerName::getChildrenOfClass($xml);
101
        $issuer = array_merge($issuer, $issuerName);
102
103
        $requestSecurityTokenTemplate = RequestSecurityTokenTemplate::getChildrenOfClass($xml);
104
        Assert::minCount($requestSecurityTokenTemplate, 1, MissingElementException::class);
105
        Assert::maxCount($requestSecurityTokenTemplate, 1, TooManyElementsException::class);
106
107
        return new static(
108
            $requestSecurityTokenTemplate[0],
109
            array_pop($issuer),
110
            self::getChildElementsFromXML($xml),
111
            self::getAttributesNSFromXML($xml),
112
        );
113
    }
114
115
116
    /**
117
     * Convert this element to XML.
118
     *
119
     * @param \DOMElement|null $parent The element we should append this element to.
120
     * @return \DOMElement
121
     */
122
    public function toXML(?DOMElement $parent = null): DOMElement
123
    {
124
        $e = $this->instantiateParentElement($parent);
125
126
        if ($this->getIssuer() !== null) {
127
            $this->getIssuer()->toXML($e);
128
        }
129
130
        $this->getRequestSecurityTokenTemplate()->toXML($e);
131
132
        foreach ($this->getElements() as $elt) {
133
            if (!$elt->isEmptyElement()) {
134
                $elt->toXML($e);
135
            }
136
        }
137
138
        foreach ($this->getAttributesNS() as $attr) {
139
            $attr->toXML($e);
140
        }
141
142
        return $e;
143
    }
144
}
145