Passed
Push — master ( 63888f...ae4cb1 )
by Tim
10:25
created

Reason::toXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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