StatusCode::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\Constants 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...
10
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
11
use SimpleSAML\XML\SchemaValidatableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementTrait;
13
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14
15
use function strval;
16
17
/**
18
 * SAML StatusCode data type.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class StatusCode extends AbstractSamlpElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\AbstractSamlpElement 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...
23
{
24
    use SchemaValidatableElementTrait;
25
26
27
    /**
28
     * Initialize a samlp:StatusCode
29
     *
30
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $Value
31
     * @param \SimpleSAML\SAML2\XML\samlp\StatusCode[] $subCodes
32
     */
33
    public function __construct(
34
        protected SAMLAnyURIValue $Value,
35
        protected array $subCodes = [],
36
    ) {
37
        Assert::maxCount($subCodes, C::UNBOUNDED_LIMIT);
38
        Assert::allIsInstanceOf($subCodes, StatusCode::class);
39
    }
40
41
42
    /**
43
     * Collect the Value
44
     *
45
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue
46
     */
47
    public function getValue(): SAMLAnyURIValue
48
    {
49
        return $this->Value;
50
    }
51
52
53
    /**
54
     * Collect the subcodes
55
     *
56
     * @return \SimpleSAML\SAML2\XML\samlp\StatusCode[]
57
     */
58
    public function getSubCodes(): array
59
    {
60
        return $this->subCodes;
61
    }
62
63
64
    /**
65
     * Convert XML into a StatusCode
66
     *
67
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
68
     *   if the qualified name of the supplied element is wrong
69
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
70
     *   if the supplied element is missing one of the mandatory attributes
71
     */
72
    public static function fromXML(DOMElement $xml): static
73
    {
74
        Assert::same($xml->localName, 'StatusCode', InvalidDOMElementException::class);
75
        Assert::same($xml->namespaceURI, StatusCode::NS, InvalidDOMElementException::class);
76
77
        return new static(
78
            self::getAttribute($xml, 'Value', SAMLAnyURIValue::class),
79
            StatusCode::getChildrenOfClass($xml),
80
        );
81
    }
82
83
84
    /**
85
     * Convert this StatusCode to XML.
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = $this->instantiateParentElement($parent);
90
        $e->setAttribute('Value', strval($this->getValue()));
91
92
        foreach ($this->getSubCodes() as $subCode) {
93
            $subCode->toXML($e);
94
        }
95
96
        return $e;
97
    }
98
}
99