RequestAuthenticated   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMustUnderstand() 0 3 1
A __construct() 0 3 1
A fromXML() 0 25 2
A toXML() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\ecp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
10
use SimpleSAML\SOAP11\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\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...
11
use SimpleSAML\SOAP11\Type\MustUnderstandValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\Type\MustUnderstandValue 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...
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
use SimpleSAML\XMLSchema\Exception\MissingAttributeException;
16
17
/**
18
 * Class representing the ECP RequestAuthenticated element.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class RequestAuthenticated extends AbstractEcpElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\ecp\AbstractEcpElement 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
     * Create a ECP RequestAuthenticated element.
29
     *
30
     * @param \SimpleSAML\SOAP11\Type\MustUnderstandValue|null $mustUnderstand
31
     */
32
    public function __construct(
33
        protected ?MustUnderstandValue $mustUnderstand,
34
    ) {
35
    }
36
37
38
    /**
39
     * Collect the value of the mustUnderstand-property
40
     *
41
     * @return \SimpleSAML\SOAP11\Type\MustUnderstandValue|null
42
     */
43
    public function getMustUnderstand(): ?MustUnderstandValue
44
    {
45
        return $this->mustUnderstand;
46
    }
47
48
49
    /**
50
     * Convert XML into a RequestAuthenticated
51
     *
52
     * @param \DOMElement $xml The XML element we should load
53
     *
54
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
55
     *   if the qualified name of the supplied element is wrong
56
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
57
     *   if the supplied element is missing any of the mandatory attributes
58
     */
59
    public static function fromXML(DOMElement $xml): static
60
    {
61
        Assert::same($xml->localName, 'RequestAuthenticated', InvalidDOMElementException::class);
62
        Assert::same($xml->namespaceURI, RequestAuthenticated::NS, InvalidDOMElementException::class);
63
64
        // Assert required attributes
65
        Assert::true(
66
            $xml->hasAttributeNS(C::NS_SOAP_ENV, 'actor'),
67
            'Missing env:actor attribute in <ecp:RequestAuthenticated>.',
68
            MissingAttributeException::class,
69
        );
70
71
        $mustUnderstand = null;
72
        if ($xml->hasAttributeNS(C::NS_SOAP_ENV, 'mustUnderstand')) {
73
            $mustUnderstand = MustUnderstandValue::fromString($xml->getAttributeNS(C::NS_SOAP_ENV, 'mustUnderstand'));
74
        }
75
76
        Assert::same(
77
            $xml->getAttributeNS(C::NS_SOAP_ENV, 'actor'),
78
            C::SOAP_ACTOR_NEXT,
79
            'Invalid value of env:actor attribute in <ecp:RequestAuthenticated>.',
80
            ProtocolViolationException::class,
81
        );
82
83
        return new static($mustUnderstand);
84
    }
85
86
87
    /**
88
     * Convert this ECP RequestAuthentication to XML.
89
     *
90
     * @param \DOMElement|null $parent The element we should append this element to.
91
     */
92
    public function toXML(?DOMElement $parent = null): DOMElement
93
    {
94
        $e = $this->instantiateParentElement($parent);
95
96
        if ($this->getMustUnderstand() !== null && $this->getMustUnderstand()->toBoolean() !== false) {
97
            $this->getMustUnderstand()->toAttribute()->toXML($e);
98
        }
99
100
        $e->setAttributeNS(C::NS_SOAP_ENV, 'SOAP-ENV:actor', C::SOAP_ACTOR_NEXT);
101
102
        return $e;
103
    }
104
}
105