SubjectConfirmation::toXML()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
10
use SimpleSAML\SAML2\XML\IdentifierTrait;
11
use SimpleSAML\XML\SchemaValidatableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementTrait;
13
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
15
16
use function array_pop;
17
18
/**
19
 * Class representing SAML 2 SubjectConfirmation element.
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
final class SubjectConfirmation extends AbstractSamlElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\AbstractSamlElement 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...
24
{
25
    use IdentifierTrait;
26
    use SchemaValidatableElementTrait;
27
28
29
    /**
30
     * Initialize (and parse) a SubjectConfirmation element.
31
     *
32
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue $method
33
     * @param \SimpleSAML\SAML2\XML\saml\IdentifierInterface|null $identifier
34
     * @param \SimpleSAML\SAML2\XML\saml\SubjectConfirmationData|null $subjectConfirmationData
35
     */
36
    public function __construct(
37
        protected SAMLAnyURIValue $method,
38
        ?IdentifierInterface $identifier = null,
39
        protected ?SubjectConfirmationData $subjectConfirmationData = null,
40
    ) {
41
        $this->setIdentifier($identifier);
42
    }
43
44
45
    /**
46
     * Collect the value of the Method-property
47
     *
48
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue
49
     */
50
    public function getMethod(): SAMLAnyURIValue
51
    {
52
        return $this->method;
53
    }
54
55
56
    /**
57
     * Collect the value of the SubjectConfirmationData-property
58
     *
59
     * @return \SimpleSAML\SAML2\XML\saml\SubjectConfirmationData|null
60
     */
61
    public function getSubjectConfirmationData(): ?SubjectConfirmationData
62
    {
63
        return $this->subjectConfirmationData;
64
    }
65
66
67
    /**
68
     * Convert XML into a SubjectConfirmation
69
     *
70
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
71
     *   if the qualified name of the supplied element is wrong
72
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
73
     *   if the supplied element is missing one of the mandatory attributes
74
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
75
     *   if too many child-elements of a type are specified
76
     */
77
    public static function fromXML(DOMElement $xml): static
78
    {
79
        Assert::same($xml->localName, 'SubjectConfirmation', InvalidDOMElementException::class);
80
        Assert::same($xml->namespaceURI, SubjectConfirmation::NS, InvalidDOMElementException::class);
81
82
        $subjectConfirmationData = SubjectConfirmationData::getChildrenOfClass($xml);
83
        Assert::maxCount(
84
            $subjectConfirmationData,
85
            1,
86
            'More than one <saml:SubjectConfirmationData> in <saml:SubjectConfirmation>.',
87
            TooManyElementsException::class,
88
        );
89
90
        return new static(
91
            self::getAttribute($xml, 'Method', SAMLAnyURIValue::class),
92
            self::getIdentifierFromXML($xml),
93
            array_pop($subjectConfirmationData),
94
        );
95
    }
96
97
98
    /**
99
     * Convert this element to XML.
100
     */
101
    public function toXML(?DOMElement $parent = null): DOMElement
102
    {
103
        $e = $this->instantiateParentElement($parent);
104
        $e->setAttribute('Method', $this->getMethod()->getValue());
105
106
        $this->getIdentifier()?->toXML($e);
0 ignored issues
show
Bug introduced by
The method toXML() does not exist on SimpleSAML\SAML2\XML\saml\IdentifierInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SimpleSAML\SAML2\XML\saml\BaseIdentifierInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
        $this->getIdentifier()?->/** @scrutinizer ignore-call */ toXML($e);
Loading history...
107
108
        if ($this->getSubjectConfirmationData() !== null && !$this->getSubjectConfirmationData()->isEmptyElement()) {
109
            $this->getSubjectConfirmationData()->toXML($e);
110
        }
111
112
        return $e;
113
    }
114
}
115