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

Subcode::getSubcode()   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\SOAP\Exception\ProtocolViolationException;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\MissingElementException;
12
use SimpleSAML\XML\Exception\TooManyElementsException;
13
14
/**
15
 * Class representing a env:Subcode element.
16
 *
17
 * @package simplesaml/xml-soap
18
 */
19
final class Subcode extends AbstractSoapElement
20
{
21
    /**
22
     * The Value element
23
     *
24
     * @var \SimpleSAML\SOAP\XML\env\Value
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\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...
25
     */
26
    protected Value $value;
27
28
    /**
29
     * The Subcode element
30
     *
31
     * @var \SimpleSAML\SOAP\XML\env\Subcode|null
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env\Subcode 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...
32
     */
33
    protected ?Subcode $subcode;
34
35
36
    /**
37
     * Initialize a soap:Subcode
38
     *
39
     * @param \SimpleSAML\SOAP\XML\env\Value $value
40
     * @param \SimpleSAML\SOAP\XML\env\Code|null $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...
41
     */
42
    public function __construct(Value $value, ?Subcode $subcode = null)
43
    {
44
        $this->setValue($value);
45
        $this->setSubcode($subcode);
46
    }
47
48
49
    /**
50
     * @return \SimpleSAML\SOAP\XML\env\Value
51
     */
52
    public function getValue(): Value
53
    {
54
        return $this->value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->value returns the type SimpleSAML\SOAP12\XML\env\Value which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Value.
Loading history...
55
    }
56
57
58
    /**
59
     * @param \SimpleSAML\SOAP\XML\env\Value $value
60
     */
61
    protected function setValue(Value $value): void
62
    {
63
        $this->value = $value;
0 ignored issues
show
Documentation Bug introduced by
It seems like $value of type SimpleSAML\SOAP12\XML\env\Value is incompatible with the declared type SimpleSAML\SOAP\XML\env\Value of property $value.

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...
64
    }
65
66
67
    /**
68
     * @return \SimpleSAML\SOAP\XML\env\Subcode|null
69
     */
70
    public function getSubcode(): ?Subcode
71
    {
72
        return $this->subcode;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->subcode also could return the type SimpleSAML\SOAP12\XML\env\Subcode which is incompatible with the documented return type SimpleSAML\SOAP\XML\env\Subcode|null.
Loading history...
73
    }
74
75
76
    /**
77
     * @param \SimpleSAML\SOAP\XML\env\Subcode|null $subcode
78
     */
79
    protected function setSubcode(?Subcode $subcode): void
80
    {
81
        $this->subcode = $subcode;
0 ignored issues
show
Documentation Bug introduced by
It seems like $subcode can also be of type SimpleSAML\SOAP12\XML\env\Subcode. However, the property $subcode is declared as type SimpleSAML\SOAP\XML\env\Subcode|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...
82
    }
83
84
85
    /**
86
     * Convert XML into an Subcode element
87
     *
88
     * @param \DOMElement $xml The XML element we should load
89
     * @return static
90
     *
91
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
92
     *   If the qualified name of the supplied element is wrong
93
     */
94
    public static function fromXML(DOMElement $xml): static
95
    {
96
        Assert::same($xml->localName, 'Subcode', InvalidDOMElementException::class);
97
        Assert::same($xml->namespaceURI, Subcode::NS, InvalidDOMElementException::class);
98
99
        $value = Value::getChildrenOfClass($xml);
100
        Assert::count($value, 1, 'Must contain exactly one Value', MissingElementException::class);
101
102
        $subcode = Subcode::getChildrenOfClass($xml);
103
        Assert::maxCount($subcode, 1, 'Cannot process more than one Subcode element.', TooManyElementsException::class);
104
105
        return new static(
106
            array_pop($value),
107
            empty($subcode) ? null : array_pop($subcode)
108
        );
109
    }
110
111
112
    /**
113
     * Convert this Subcode to XML.
114
     *
115
     * @param \DOMElement|null $parent The element we should add this subcode to.
116
     * @return \DOMElement This Subcode-element.
117
     */
118
    public function toXML(DOMElement $parent = null): DOMElement
119
    {
120
        $e = $this->instantiateParentElement($parent);
121
122
        $this->getValue()->toXML($e);
123
        $this->getSubcode()?->toXML($e);
124
125
        return $e;
126
    }
127
}
128