Status::getStatusMessage()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Exception\ProtocolViolationException;
11
use SimpleSAML\XML\SchemaValidatableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementTrait;
13
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14
use SimpleSAML\XMLSchema\Exception\MissingElementException;
15
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
16
17
use function array_pop;
18
use function strval;
19
20
/**
21
 * SAML Status data type.
22
 *
23
 * @package simplesamlphp/saml2
24
 */
25
final class Status 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...
26
{
27
    use SchemaValidatableElementTrait;
28
29
30
    /**
31
     * Initialize a samlp:Status
32
     *
33
     * @param \SimpleSAML\SAML2\XML\samlp\StatusCode $statusCode
34
     * @param \SimpleSAML\SAML2\XML\samlp\StatusMessage|null $statusMessage
35
     * @param \SimpleSAML\SAML2\XML\samlp\StatusDetail[] $statusDetails
36
     */
37
    public function __construct(
38
        protected StatusCode $statusCode,
39
        protected ?StatusMessage $statusMessage = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\StatusMessage 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...
40
        protected array $statusDetails = [],
41
    ) {
42
        Assert::oneOf(
43
            strval($statusCode->getValue()),
44
            [
45
                C::STATUS_SUCCESS,
46
                C::STATUS_REQUESTER,
47
                C::STATUS_RESPONDER,
48
                C::STATUS_VERSION_MISMATCH,
49
            ],
50
            'Invalid top-level status code:  %s',
51
            ProtocolViolationException::class,
52
        );
53
        Assert::maxCount($statusDetails, C::UNBOUNDED_LIMIT);
54
        Assert::allIsInstanceOf($statusDetails, StatusDetail::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\StatusDetail 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...
55
    }
56
57
58
    /**
59
     * Collect the StatusCode
60
     *
61
     * @return \SimpleSAML\SAML2\XML\samlp\StatusCode
62
     */
63
    public function getStatusCode(): StatusCode
64
    {
65
        return $this->statusCode;
66
    }
67
68
69
    /**
70
     * Collect the value of the statusMessage
71
     *
72
     * @return \SimpleSAML\SAML2\XML\samlp\StatusMessage|null
73
     */
74
    public function getStatusMessage(): ?StatusMessage
75
    {
76
        return $this->statusMessage;
77
    }
78
79
80
    /**
81
     * Collect the value of the statusDetails property
82
     *
83
     * @return \SimpleSAML\SAML2\XML\samlp\StatusDetail[]
84
     */
85
    public function getStatusDetails(): array
86
    {
87
        return $this->statusDetails;
88
    }
89
90
91
    /**
92
     * Convert XML into a Status
93
     *
94
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
95
     *   if the qualified name of the supplied element is wrong
96
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
97
     *   if too many child-elements of a type are specified
98
     * @throws \SimpleSAML\XMLSchema\Exception\MissingElementException
99
     *   if one of the mandatory child-elements is missing
100
     */
101
    public static function fromXML(DOMElement $xml): static
102
    {
103
        Assert::same($xml->localName, 'Status', InvalidDOMElementException::class);
104
        Assert::same($xml->namespaceURI, Status::NS, InvalidDOMElementException::class);
105
106
        $statusCode = StatusCode::getChildrenOfClass($xml);
107
        Assert::minCount($statusCode, 1, MissingElementException::class);
108
        Assert::count($statusCode, 1, TooManyElementsException::class);
109
110
        $statusMessage = StatusMessage::getChildrenOfClass($xml);
111
        Assert::maxCount($statusMessage, 1, TooManyElementsException::class);
112
113
        $statusDetails = StatusDetail::getChildrenOfClass($xml);
114
115
        return new static(
116
            array_pop($statusCode),
117
            array_pop($statusMessage),
118
            $statusDetails,
119
        );
120
    }
121
122
123
    /**
124
     * Convert this Status to XML.
125
     */
126
    public function toXML(?DOMElement $parent = null): DOMElement
127
    {
128
        $e = $this->instantiateParentElement($parent);
129
130
        $this->getStatusCode()->toXML($e);
131
132
        $this->getStatusMessage()?->toXML($e);
133
134
        foreach ($this->getStatusDetails() as $sd) {
135
            if (!$sd->isEmptyElement()) {
136
                $sd->toXML($e);
137
            }
138
        }
139
140
        return $e;
141
    }
142
}
143