Passed
Push — master ( c726f3...c686fd )
by Tim
10:07
created

Fault::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP12\XML\env;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
13
/**
14
 * Class representing a env:Fault element.
15
 *
16
 * @package simplesaml/xml-soap
17
 */
18
final class Fault extends AbstractSoapElement
19
{
20
    /**
21
     * The Code element
22
     *
23
     * @var \SimpleSAML\SOAP\XML\env\Code
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\Code 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...
24
     */
25
    protected Code $code;
26
27
    /**
28
     * The Reason element
29
     *
30
     * @var \SimpleSAML\SOAP\XML\env\Reason
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\Reason 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...
31
     */
32
    protected Reason $reason;
33
34
    /**
35
     * The Node element
36
     *
37
     * @var \SimpleSAML\SOAP\XML\env\Node|null
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\Node 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
    protected ?Node $node;
40
41
    /**
42
     * The Role element
43
     *
44
     * @var \SimpleSAML\SOAP\XML\env\Role|null
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\Role 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...
45
     */
46
    protected ?Role $role;
47
48
    /**
49
     * The Detail element
50
     *
51
     * @var \SimpleSAML\SOAP\XML\env\Detail|null
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\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...
52
     */
53
    protected ?Detail $detail;
54
55
56
    /**
57
     * Initialize a env:Fault
58
     *
59
     * @param \SimpleSAML\SOAP\XML\env\Code $code
60
     * @param \SimpleSAML\SOAP\XML\env\Reason $reason
61
     * @param \SimpleSAML\SOAP\XML\env\Node|null $node
62
     * @param \SimpleSAML\SOAP\XML\env\Role|null $role
63
     * @param \SimpleSAML\SOAP\XML\env\Detail|null $detail
64
     */
65
    public function __construct(
66
        Code $code,
67
        Reason $reason,
68
        ?Node $node = null,
69
        ?Role $role = null,
70
        ?Detail $detail = null
71
    ) {
72
        $this->setCode($code);
73
        $this->setReason($reason);
74
        $this->setNode($node);
75
        $this->setRole($role);
76
        $this->setDetail($detail);
77
    }
78
79
80
    /**
81
     * @return \SimpleSAML\SOAP\XML\env\Code
82
     */
83
    public function getCode(): Code
84
    {
85
        return $this->code;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->code returns the type SimpleSAML\SOAP12\XML\env\Code which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Code.
Loading history...
86
    }
87
88
89
    /**
90
     * @param \SimpleSAML\SOAP\XML\env\Code $code
91
     */
92
    protected function setCode(Code $code): void
93
    {
94
        $this->code = $code;
0 ignored issues
show
Documentation Bug introduced by
It seems like $code of type SimpleSAML\SOAP12\XML\env\Code is incompatible with the declared type SimpleSAML\SOAP\XML\env\Code of property $code.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
95
    }
96
97
98
    /**
99
     * @return \SimpleSAML\SOAP\XML\env\Reason
100
     */
101
    public function getReason(): Reason
102
    {
103
        return $this->reason;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->reason returns the type SimpleSAML\SOAP12\XML\env\Reason which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Reason.
Loading history...
104
    }
105
106
107
    /**
108
     * @param \SimpleSAML\SOAP\XML\env\Reason $reason
109
     */
110
    protected function setReason(Reason $reason): void
111
    {
112
        $this->reason = $reason;
0 ignored issues
show
Documentation Bug introduced by
It seems like $reason of type SimpleSAML\SOAP12\XML\env\Reason is incompatible with the declared type SimpleSAML\SOAP\XML\env\Reason of property $reason.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
113
    }
114
115
116
    /**
117
     * @return \SimpleSAML\SOAP\XML\env\Node|null
118
     */
119
    public function getNode(): ?Node
120
    {
121
        return $this->node;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->node also could return the type SimpleSAML\SOAP12\XML\env\Node which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Node|null.
Loading history...
122
    }
123
124
125
    /**
126
     * @param \SimpleSAML\SOAP\XML\env\Node|null $node
127
     */
128
    protected function setNode(?Node $node): void
129
    {
130
        $this->node = $node;
0 ignored issues
show
Documentation Bug introduced by
It seems like $node can also be of type SimpleSAML\SOAP12\XML\env\Node. However, the property $node is declared as type SimpleSAML\SOAP\XML\env\Node|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
131
    }
132
133
134
    /**
135
     * @return \SimpleSAML\SOAP\XML\env\Role|null
136
     */
137
    public function getRole(): ?Role
138
    {
139
        return $this->role;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->role also could return the type SimpleSAML\SOAP12\XML\env\Role which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Role|null.
Loading history...
140
    }
141
142
143
    /**
144
     * @param \SimpleSAML\SOAP\XML\env\Role|null $role
145
     */
146
    protected function setRole(?Role $role): void
147
    {
148
        $this->role = $role;
0 ignored issues
show
Documentation Bug introduced by
It seems like $role can also be of type SimpleSAML\SOAP12\XML\env\Role. However, the property $role is declared as type SimpleSAML\SOAP\XML\env\Role|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
149
    }
150
151
152
    /**
153
     * @return \SimpleSAML\SOAP\XML\env\Detail|null
154
     */
155
    public function getDetail(): ?Detail
156
    {
157
        return $this->detail;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->detail also could return the type SimpleSAML\SOAP12\XML\env\Detail which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Detail|null.
Loading history...
158
    }
159
160
161
    /**
162
     * @param \SimpleSAML\SOAP\XML\env\Detail|null $detail
163
     */
164
    protected function setDetail(?Detail $detail): void
165
    {
166
        $this->detail = $detail;
0 ignored issues
show
Documentation Bug introduced by
It seems like $detail can also be of type SimpleSAML\SOAP12\XML\env\Detail. However, the property $detail is declared as type SimpleSAML\SOAP\XML\env\Detail|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
167
    }
168
169
170
    /**
171
     * Convert XML into an Fault element
172
     *
173
     * @param \DOMElement $xml The XML element we should load
174
     * @return static
175
     *
176
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
177
     *   If the qualified name of the supplied element is wrong
178
     */
179
    public static function fromXML(DOMElement $xml): static
180
    {
181
        Assert::same($xml->localName, 'Fault', InvalidDOMElementException::class);
182
        Assert::same($xml->namespaceURI, Fault::NS, InvalidDOMElementException::class);
183
184
        $code = Code::getChildrenOfClass($xml);
185
        Assert::count($code, 1, 'Must contain exactly one Code', MissingElementException::class);
186
187
        $reason = Reason::getChildrenOfClass($xml);
188
        Assert::count($reason, 1, 'Must contain exactly one Reason', MissingElementException::class);
189
190
        $node = Node::getChildrenOfClass($xml);
191
        Assert::maxCount($node, 1, 'Cannot process more than one Node element.', TooManyElementsException::class);
192
193
        $role = Role::getChildrenOfClass($xml);
194
        Assert::maxCount($role, 1, 'Cannot process more than one Role element.', TooManyElementsException::class);
195
196
        $detail = Detail::getChildrenOfClass($xml);
197
        Assert::maxCount($detail, 1, 'Cannot process more than one Detail element.', TooManyElementsException::class);
198
199
        return new self(
200
            array_pop($code),
201
            array_pop($reason),
202
            empty($node) ? null : array_pop($node),
203
            empty($role) ? null : array_pop($role),
204
            empty($detail) ? null : array_pop($detail)
205
        );
206
    }
207
208
209
    /**
210
     * Convert this Fault to XML.
211
     *
212
     * @param \DOMElement|null $parent The element we should add this fault to.
213
     * @return \DOMElement This Fault-element.
214
     */
215
    public function toXML(DOMElement $parent = null): DOMElement
216
    {
217
        $e = $this->instantiateParentElement($parent);
218
219
        $this->getCode()->toXML($e);
220
        $this->getReason()->toXML($e);
221
222
        $this->getNode()?->toXML($e);
223
        $this->getRole()?->toXML($e);
224
225
        if ($this->getDetail() !== null && !$this->getDetail()->isEmptyElement()) {
226
            $this->getDetail()->toXML($e);
227
        }
228
229
        return $e;
230
    }
231
}
232