Text::getLanguage()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\SOAP12\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP12\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\XML\Type\LangValue;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingAttributeException;
13
use SimpleSAML\XMLSchema\Type\StringValue;
14
15
use function strval;
16
17
/**
18
 * Class representing a env:Text element.
19
 *
20
 * @package simplesaml/xml-soap
21
 */
22
final class Text 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...
23
{
24
    /**
25
     * Initialize a env:Text
26
     *
27
     * @param \SimpleSAML\XML\Type\LangValue $language
28
     * @param \SimpleSAML\XMLSchema\Type\StringValue $content
29
     */
30
    public function __construct(
31
        protected LangValue $language,
32
        protected StringValue $content,
33
    ) {
34
    }
35
36
37
    /**
38
     * Collect the value of the language-property
39
     *
40
     * @return \SimpleSAML\XML\Type\LangValue
41
     */
42
    public function getLanguage(): LangValue
43
    {
44
        return $this->language;
45
    }
46
47
48
    /**
49
     * Collect the value of the content-property
50
     *
51
     * @return \SimpleSAML\XMLSchema\Type\StringValue
52
     */
53
    public function getContent(): StringValue
54
    {
55
        return $this->content;
56
    }
57
58
59
    /**
60
     * Convert XML into a env:Text element
61
     *
62
     * @param \DOMElement $xml The XML element we should load
63
     *
64
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
65
     *   If the qualified name of the supplied element is wrong
66
     */
67
    public static function fromXML(DOMElement $xml): static
68
    {
69
        Assert::same($xml->localName, 'Text', InvalidDOMElementException::class);
70
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
71
        Assert::true(
72
            $xml->hasAttributeNS(C::NS_XML, 'lang'),
73
            'Missing xml:lang from ' . static::getLocalName(),
74
            MissingAttributeException::class,
75
        );
76
77
        return new static(
78
            LangValue::fromString($xml->getAttributeNS(C::NS_XML, 'lang')),
79
            StringValue::fromString($xml->textContent),
80
        );
81
    }
82
83
84
    /**
85
     * Convert this Text element to XML.
86
     *
87
     * @param \DOMElement|null $parent The element we should append this Text element to.
88
     */
89
    public function toXML(?DOMElement $parent = null): DOMElement
90
    {
91
        $e = $this->instantiateParentElement($parent);
92
        $e->textContent = strval($this->getContent());
93
94
        $this->getLanguage()->toAttribute()->toXML($e);
95
96
        return $e;
97
    }
98
}
99