AudienceRestriction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
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\Exception\SchemaViolationException;
14
15
/**
16
 * SAML AudienceRestriction data type.
17
 *
18
 * @package simplesamlphp/saml2
19
 */
20
final class AudienceRestriction extends AbstractConditionType implements SchemaValidatableElementInterface
21
{
22
    use SchemaValidatableElementTrait;
23
24
25
    /**
26
     * Initialize a saml:AudienceRestriction
27
     *
28
     * @param \SimpleSAML\SAML2\XML\saml\Audience[] $audience
29
     */
30
    public function __construct(
31
        protected array $audience,
32
    ) {
33
        Assert::minCount($audience, 1, SchemaViolationException::class);
34
        Assert::maxCount($audience, C::UNBOUNDED_LIMIT);
35
        Assert::allIsInstanceOf($audience, Audience::class, SchemaViolationException::class);
36
    }
37
38
39
    /**
40
     * Collect the audience
41
     *
42
     * @return \SimpleSAML\SAML2\XML\saml\Audience[]
43
     */
44
    public function getAudience(): array
45
    {
46
        return $this->audience;
47
    }
48
49
50
    /**
51
     * Convert XML into an AudienceRestriction
52
     *
53
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
54
     *   if the qualified name of the supplied element is wrong
55
     */
56
    public static function fromXML(DOMElement $xml): static
57
    {
58
        Assert::same($xml->localName, 'AudienceRestriction', InvalidDOMElementException::class);
59
        Assert::same($xml->namespaceURI, AudienceRestriction::NS, InvalidDOMElementException::class);
60
61
        $audience = Audience::getChildrenOfClass($xml);
62
63
        return new static($audience);
64
    }
65
66
67
    /**
68
     * Convert this Audience to XML.
69
     */
70
    public function toXML(?DOMElement $parent = null): DOMElement
71
    {
72
        $e = $this->instantiateParentElement($parent);
73
74
        foreach ($this->getAudience() as $audience) {
75
            $audience->toXML($e);
76
        }
77
78
        return $e;
79
    }
80
}
81