Reason::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP12\XML;
6
7
use DOMElement;
8
use SimpleSAML\SOAP12\Assert\Assert;
9
use SimpleSAML\XML\Constants as C;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12
13
/**
14
 * Class representing a env:Reason element.
15
 *
16
 * @package simplesaml/xml-soap
17
 */
18
final class Reason extends AbstractSoapElement
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP12\XML\AbstractSoapElement 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...
19
{
20
    /**
21
     * Initialize a env:Reason
22
     *
23
     * @param \SimpleSAML\SOAP12\XML\Text[] $text
24
     */
25
    public function __construct(
26
        protected array $text,
27
    ) {
28
        Assert::maxCount($text, C::UNBOUNDED_LIMIT);
29
        Assert::minCount($text, 1, SchemaViolationException::class);
30
        Assert::allIsInstanceOf($text, Text::class, SchemaViolationException::class);
31
    }
32
33
34
    /**
35
     * @return \SimpleSAML\SOAP12\XML\Text[]
36
     */
37
    public function getText(): array
38
    {
39
        return $this->text;
40
    }
41
42
43
    /**
44
     * Convert XML into a Value
45
     *
46
     * @param \DOMElement $xml The XML element we should load
47
     *
48
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
49
     *   If the qualified name of the supplied element is wrong
50
     */
51
    public static function fromXML(DOMElement $xml): static
52
    {
53
        Assert::same($xml->localName, 'Reason', InvalidDOMElementException::class);
54
        Assert::same($xml->namespaceURI, Reason::NS, InvalidDOMElementException::class);
55
56
        $text = Text::getChildrenOfClass($xml);
57
        Assert::minCount($text, 1, SchemaViolationException::class);
58
59
        return new static($text);
60
    }
61
62
63
    /**
64
     * Convert this element to XML.
65
     *
66
     * @param \DOMElement|null $parent The element we should append this element to.
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = $this->instantiateParentElement($parent);
71
72
        foreach ($this->getText() as $text) {
73
            $text->toXML($e);
74
        }
75
76
        return $e;
77
    }
78
}
79