ProxyRestriction::getCount()   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\saml;
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
/**
16
 * @package simplesamlphp/saml2
17
 */
18
final class ProxyRestriction extends AbstractConditionType implements SchemaValidatableElementInterface
19
{
20
    use SchemaValidatableElementTrait;
21
22
23
    /**
24
     * ProxyRestriction constructor.
25
     *
26
     * @param \SimpleSAML\SAML2\XML\saml\Audience[] $audience
27
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue|null $count
28
     */
29
    public function __construct(
30
        protected array $audience = [],
31
        protected ?NonNegativeIntegerValue $count = null,
32
    ) {
33
        Assert::maxCount($audience, C::UNBOUNDED_LIMIT);
34
        Assert::allIsInstanceOf($audience, Audience::class);
35
    }
36
37
38
    /**
39
     * Get the value of the count-attribute.
40
     *
41
     * @return \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue|null
42
     */
43
    public function getCount(): ?NonNegativeIntegerValue
44
    {
45
        return $this->count;
46
    }
47
48
49
    /**
50
     * Get the value of the audience-attribute.
51
     *
52
     * @return \SimpleSAML\SAML2\XML\saml\Audience[]
53
     */
54
    public function getAudience(): array
55
    {
56
        return $this->audience;
57
    }
58
59
60
    /**
61
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
62
     *   if the qualified name of the supplied element is wrong
63
     */
64
    public static function fromXML(DOMElement $xml): static
65
    {
66
        Assert::same($xml->localName, 'ProxyRestriction', InvalidDOMElementException::class);
67
        Assert::same($xml->namespaceURI, ProxyRestriction::NS, InvalidDOMElementException::class);
68
69
        $count = self::getOptionalAttribute($xml, 'Count', NonNegativeIntegerValue::class, null);
70
        $audience = Audience::getChildrenOfClass($xml);
71
72
        return new static($audience, $count);
73
    }
74
75
76
    /**
77
     * Convert this Condition to XML.
78
     */
79
    public function toXML(?DOMElement $parent = null): DOMElement
80
    {
81
        $e = $this->instantiateParentElement($parent);
82
83
        if ($this->getCount() !== null) {
84
            $e->setAttribute('Count', $this->getCount()->getValue());
85
        }
86
87
        foreach ($this->getAudience() as $audience) {
88
            $audience->toXML($e);
89
        }
90
91
        return $e;
92
    }
93
}
94