Scoping::getRequesterId()   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
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\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\XML\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\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\SchemaValidatableElementInterface;
11
use SimpleSAML\XML\SchemaValidatableElementTrait;
12
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
13
use SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue 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...
14
15
use function array_pop;
16
use function strval;
17
18
/**
19
 * Class for handling SAML2 Scoping.
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
final class Scoping extends AbstractSamlpElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\AbstractSamlpElement 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
    use SchemaValidatableElementTrait;
26
27
28
    /**
29
     * Initialize a Scoping element.
30
     *
31
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue|null $proxyCount
32
     * @param \SimpleSAML\SAML2\XML\samlp\IDPList|null $IDPList
33
     * @param \SimpleSAML\SAML2\XML\samlp\RequesterID[] $requesterId
34
     */
35
    public function __construct(
36
        protected ?NonNegativeIntegerValue $proxyCount = null,
37
        protected ?IDPList $IDPList = null,
38
        protected array $requesterId = [],
39
    ) {
40
        Assert::maxCount($requesterId, C::UNBOUNDED_LIMIT);
41
        Assert::allIsInstanceOf($requesterId, RequesterID::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\samlp\RequesterID 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...
42
    }
43
44
45
    /**
46
     * @return \SimpleSAML\SAML2\XML\samlp\IDPList|null
47
     */
48
    public function getIDPList(): ?IDPList
49
    {
50
        return $this->IDPList;
51
    }
52
53
54
    /**
55
     * @return \SimpleSAML\SAML2\XML\samlp\RequesterID[]
56
     */
57
    public function getRequesterId(): array
58
    {
59
        return $this->requesterId;
60
    }
61
62
63
    /**
64
     * @return \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue|null
65
     */
66
    public function getProxyCount(): ?NonNegativeIntegerValue
67
    {
68
        return $this->proxyCount;
69
    }
70
71
72
    /**
73
     * Test if an object, at the state it's in, would produce an empty XML-element
74
     */
75
    public function isEmptyElement(): bool
76
    {
77
        return empty($this->getProxyCount())
78
            && empty($this->getIDPList())
79
            && empty($this->getRequesterId());
80
    }
81
82
83
    /**
84
     * Convert XML into a Scoping-element
85
     *
86
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
87
     *   if the qualified name of the supplied element is wrong
88
     */
89
    public static function fromXML(DOMElement $xml): static
90
    {
91
        Assert::same($xml->localName, 'Scoping', InvalidDOMElementException::class);
92
        Assert::same($xml->namespaceURI, Scoping::NS, InvalidDOMElementException::class);
93
94
        $idpList = IDPList::getChildrenOfClass($xml);
95
        $requesterId = RequesterID::getChildrenOfClass($xml);
96
97
        return new static(
98
            self::getOptionalAttribute($xml, 'ProxyCount', NonNegativeIntegerValue::class, null),
99
            array_pop($idpList),
100
            $requesterId,
101
        );
102
    }
103
104
105
    /**
106
     * Convert this Scoping to XML.
107
     */
108
    public function toXML(?DOMElement $parent = null): DOMElement
109
    {
110
        $e = $this->instantiateParentElement($parent);
111
112
        if ($this->getProxyCount() !== null) {
113
            $e->setAttribute('ProxyCount', strval($this->getProxyCount()));
114
        }
115
116
        $this->getIDPList()?->toXML($e);
117
118
        foreach ($this->getRequesterId() as $rid) {
119
            $rid->toXML($e);
120
        }
121
122
        return $e;
123
    }
124
}
125