Code   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 72
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 8 1
A getSubcode() 0 3 1
A __construct() 0 4 1
A getValue() 0 3 1
A fromXML() 0 14 2
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\XMLSchema\Exception\InvalidDOMElementException;
10
use SimpleSAML\XMLSchema\Exception\MissingElementException;
11
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
12
13
/**
14
 * Class representing a env:Code element.
15
 *
16
 * @package simplesaml/xml-soap
17
 */
18
final class Code 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 soap:Code
22
     *
23
     * @param \SimpleSAML\SOAP12\XML\Value $value
24
     * @param \SimpleSAML\SOAP12\XML\Subcode|null $subcode
25
     */
26
    public function __construct(
27
        protected Value $value,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP12\XML\Value 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...
28
        protected ?Subcode $subcode = null,
29
    ) {
30
    }
31
32
33
    /**
34
     * @return \SimpleSAML\SOAP12\XML\Value
35
     */
36
    public function getValue(): Value
37
    {
38
        return $this->value;
39
    }
40
41
42
    /**
43
     * @return \SimpleSAML\SOAP12\XML\Subcode|null
44
     */
45
    public function getSubcode(): ?Subcode
46
    {
47
        return $this->subcode;
48
    }
49
50
51
    /**
52
     * Convert XML into an Code element
53
     *
54
     * @param \DOMElement $xml The XML element we should load
55
     *
56
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
57
     *   If the qualified name of the supplied element is wrong
58
     */
59
    public static function fromXML(DOMElement $xml): static
60
    {
61
        Assert::same($xml->localName, 'Code', InvalidDOMElementException::class);
62
        Assert::same($xml->namespaceURI, Code::NS, InvalidDOMElementException::class);
63
64
        $value = Value::getChildrenOfClass($xml);
65
        Assert::count($value, 1, 'Must contain exactly one Value', MissingElementException::class);
66
67
        $subcode = Subcode::getChildrenOfClass($xml);
68
        Assert::maxCount($subcode, 1, 'Cannot process more than one Subcode element.', TooManyElementsException::class);
69
70
        return new static(
71
            array_pop($value),
72
            empty($subcode) ? null : array_pop($subcode),
73
        );
74
    }
75
76
77
    /**
78
     * Convert this Code to XML.
79
     *
80
     * @param \DOMElement|null $parent The element we should add this code to.
81
     */
82
    public function toXML(?DOMElement $parent = null): DOMElement
83
    {
84
        $e = $this->instantiateParentElement($parent);
85
86
        $this->value->toXML($e);
87
        $this->subcode?->toXML($e);
88
89
        return $e;
90
    }
91
}
92