Fault::getFaultActor()   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\SOAP11\XML;
6
7
use DOMElement;
8
use SimpleSAML\SOAP11\Assert\Assert;
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14
15
/**
16
 * Class representing a SOAP-ENV:Fault element.
17
 *
18
 * @package simplesaml/xml-soap
19
 */
20
final class Fault extends AbstractSoapElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\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...
21
{
22
    use SchemaValidatableElementTrait;
23
24
25
    /**
26
     * Initialize a SOAP-ENV:Fault
27
     *
28
     * @param \SimpleSAML\SOAP11\XML\FaultCode $faultCode
29
     * @param \SimpleSAML\SOAP11\XML\FaultString $faultString
30
     * @param \SimpleSAML\SOAP11\XML\FaultActor|null $faultActor
31
     * @param \SimpleSAML\SOAP11\XML\Detail|null $detail
32
     */
33
    public function __construct(
34
        protected FaultCode $faultCode,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\XML\FaultCode 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...
35
        protected FaultString $faultString,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\XML\FaultString 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...
36
        protected ?FaultActor $faultActor = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\XML\FaultActor 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...
37
        protected ?Detail $detail = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP11\XML\Detail 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...
38
    ) {
39
    }
40
41
42
    /**
43
     * @return \SimpleSAML\SOAP11\XML\FaultCode
44
     */
45
    public function getFaultCode(): FaultCode
46
    {
47
        return $this->faultCode;
48
    }
49
50
51
    /**
52
     * @return \SimpleSAML\SOAP11\XML\FaultString
53
     */
54
    public function getFaultString(): FaultString
55
    {
56
        return $this->faultString;
57
    }
58
59
60
    /**
61
     * @return \SimpleSAML\SOAP11\XML\FaultActor|null
62
     */
63
    public function getFaultActor(): ?FaultActor
64
    {
65
        return $this->faultActor;
66
    }
67
68
69
    /**
70
     * @return \SimpleSAML\SOAP11\XML\Detail|null
71
     */
72
    public function getDetail(): ?Detail
73
    {
74
        return $this->detail;
75
    }
76
77
78
    /**
79
     * Convert XML into an Fault element
80
     *
81
     * @param \DOMElement $xml The XML element we should load
82
     *
83
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
84
     *   If the qualified name of the supplied element is wrong
85
     */
86
    public static function fromXML(DOMElement $xml): static
87
    {
88
        Assert::same($xml->localName, 'Fault', InvalidDOMElementException::class);
89
        Assert::same($xml->namespaceURI, Fault::NS, InvalidDOMElementException::class);
90
91
        $faultCode = FaultCode::getChildrenOfClass($xml);
92
        Assert::count($faultCode, 1, 'Must contain exactly one faultcode', MissingElementException::class);
93
94
        $faultString = FaultString::getChildrenOfClass($xml);
95
        Assert::count($faultString, 1, 'Must contain exactly one faultstring', MissingElementException::class);
96
97
        $faultActor = FaultActor::getChildrenOfClass($xml);
98
        Assert::maxCount(
99
            $faultActor,
100
            1,
101
            'Cannot process more than one faultactor element.',
102
            TooManyElementsException::class,
103
        );
104
105
        $detail = Detail::getChildrenOfClass($xml);
106
        Assert::maxCount($detail, 1, 'Cannot process more than one detail element.', TooManyElementsException::class);
107
108
        return new self(
109
            array_pop($faultCode),
110
            array_pop($faultString),
111
            array_pop($faultActor),
112
            array_pop($detail),
113
        );
114
    }
115
116
117
    /**
118
     * Convert this Fault to XML.
119
     *
120
     * @param \DOMElement|null $parent The element we should add this fault to.
121
     */
122
    public function toXML(?DOMElement $parent = null): DOMElement
123
    {
124
        $e = $this->instantiateParentElement($parent);
125
126
        $this->getFaultCode()->toXML($e);
127
        $this->getFaultString()->toXML($e);
128
        $this->getFaultActor()?->toXML($e);
129
130
        if ($this->getDetail() !== null && !$this->getDetail()->isEmptyElement()) {
131
            $this->getDetail()->toXML($e);
132
        }
133
134
        return $e;
135
    }
136
}
137