Evidence::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 4
dl 0
loc 14
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\Exception\SchemaViolationException;
14
15
/**
16
 * Class representing a saml:Evidence element.
17
 *
18
 * @package simplesaml/saml2
19
 */
20
final class Evidence extends AbstractSamlElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\AbstractSamlElement 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...
21
{
22
    use SchemaValidatableElementTrait;
23
24
25
    /**
26
     * @param \SimpleSAML\SAML2\XML\saml\AssertionIDRef[] $assertionIDRef
27
     * @param \SimpleSAML\SAML2\XML\saml\AssertionURIRef[] $assertionURIRef
28
     * @param \SimpleSAML\SAML2\XML\saml\Assertion[] $assertion
29
     * @param \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[] $encryptedAssertion
30
     */
31
    public function __construct(
32
        protected array $assertionIDRef = [],
33
        protected array $assertionURIRef = [],
34
        protected array $assertion = [],
35
        protected array $encryptedAssertion = [],
36
    ) {
37
        Assert::maxCount($assertionIDRef, C::UNBOUNDED_LIMIT);
38
        Assert::maxCount($assertionURIRef, C::UNBOUNDED_LIMIT);
39
        Assert::maxCount($assertion, C::UNBOUNDED_LIMIT);
40
        Assert::maxCount($encryptedAssertion, C::UNBOUNDED_LIMIT);
41
        Assert::allIsInstanceOf($assertionIDRef, AssertionIDRef::class, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\AssertionIDRef 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
        Assert::allIsInstanceOf($assertionURIRef, AssertionURIRef::class, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\saml\AssertionURIRef 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...
43
        Assert::allIsInstanceOf($assertion, Assertion::class, SchemaViolationException::class);
44
        Assert::allIsInstanceOf($encryptedAssertion, EncryptedAssertion::class, SchemaViolationException::class);
45
    }
46
47
48
    /**
49
     * Test if an object, at the state it's in, would produce an empty XML-element
50
     */
51
    public function isEmptyElement(): bool
52
    {
53
        return empty($this->assertionIDRef)
54
            && empty($this->assertionURIRef)
55
            && empty($this->assertion)
56
            && empty($this->encryptedAssertion);
57
    }
58
59
60
    /**
61
     * @return \SimpleSAML\SAML2\XML\saml\AssertionIDRef[]
62
     */
63
    public function getAssertionIDRef(): array
64
    {
65
        return $this->assertionIDRef;
66
    }
67
68
69
    /**
70
     * @return \SimpleSAML\SAML2\XML\saml\AssertionURIRef[]
71
     */
72
    public function getAssertionURIRef(): array
73
    {
74
        return $this->assertionURIRef;
75
    }
76
77
78
    /**
79
     * @return \SimpleSAML\SAML2\XML\saml\Assertion[]
80
     */
81
    public function getAssertion(): array
82
    {
83
        return $this->assertion;
84
    }
85
86
87
    /**
88
     * @return \SimpleSAML\SAML2\XML\saml\EncryptedAssertion[]
89
     */
90
    public function getEncryptedAssertion(): array
91
    {
92
        return $this->encryptedAssertion;
93
    }
94
95
96
    /**
97
     * Convert XML into an Evidence
98
     *
99
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
100
     *   If the qualified name of the supplied element is wrong
101
     */
102
    public static function fromXML(DOMElement $xml): static
103
    {
104
        $qualifiedName = static::getClassName(static::class);
105
        Assert::eq(
106
            $xml->localName,
107
            $qualifiedName,
108
            'Unexpected name for endpoint: ' . $xml->localName . '. Expected: ' . $qualifiedName . '.',
109
            InvalidDOMElementException::class,
110
        );
111
112
        $assertionIDRef = AssertionIDRef::getChildrenOfClass($xml);
113
        $assertionURIRef = AssertionURIRef::getChildrenOfClass($xml);
114
        $assertion = Assertion::getChildrenOfClass($xml);
115
        $encryptedAssertion = EncryptedAssertion::getChildrenOfClass($xml);
116
117
        return new static(
118
            $assertionIDRef,
119
            $assertionURIRef,
120
            $assertion,
121
            $encryptedAssertion,
122
        );
123
    }
124
125
126
    /**
127
     * Convert this Evidence to XML.
128
     */
129
    public function toXML(?DOMElement $parent = null): DOMElement
130
    {
131
        $e = $this->instantiateParentElement($parent);
132
133
        foreach ($this->getAssertionIDRef() as $assertionIDRef) {
134
            $assertionIDRef->toXML($e);
135
        }
136
137
        foreach ($this->getAssertionURIRef() as $assertionURIRef) {
138
            $assertionURIRef->toXML($e);
139
        }
140
141
        foreach ($this->getAssertion() as $assertion) {
142
            $assertion->toXML($e);
143
        }
144
145
        foreach ($this->getEncryptedAssertion() as $encryptedAssertion) {
146
            $encryptedAssertion->toXML($e);
147
        }
148
149
        return $e;
150
    }
151
}
152