Passed
Push — master ( c7072b...499637 )
by Tim
02:23
created

AbstractSPKIDataType::getTuples()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\SchemaViolationException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
use SimpleSAML\XML\SerializableElementInterface;
13
use SimpleSAML\XML\XsNamespace as NS;
14
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
15
16
/**
17
 * Abstract class representing the SPKIDataType.
18
 *
19
 * @package simplesamlphp/xml-security
20
 */
21
abstract class AbstractSPKIDataType extends AbstractDsElement
22
{
23
    /**
24
     * Initialize a SPKIData element.
25
     *
26
     * @param array<\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, SimpleSAML\XML\SerializableElementInterface|null> $tuples
27
     */
28
    final public function __construct(
29
        protected array $tuples,
30
    ) {
31
        Assert::allIsArray($tuples, SchemaViolationException::class);
32
33
        foreach ($tuples as $tuple) {
34
            list($spkisExp, $other) = $tuple;
35
            Assert::instanceOf($spkisExp, SPKISexp::class, SchemaViolationException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\ds\SPKISexp 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...
36
            Assert::instanceOf($other, SerializableElementInterface::class, SchemaViolationException::class);
37
        }
38
    }
39
40
41
    /**
42
     * Collect the value of the SPKISexp-property
43
     *
44
     * @return array<\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, SimpleSAML\XML\SerializableElementInterface|null>
45
     */
46
    public function getTuples(): array
47
    {
48
        return $this->tuples;
49
    }
50
51
52
    /**
53
     * Convert XML into a SPKIData
54
     *
55
     * @param \DOMElement $xml The XML element we should load
56
     * @return static
57
     *
58
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
59
     *   If the qualified name of the supplied element is wrong
60
     */
61
    public static function fromXML(DOMElement $xml): static
62
    {
63
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
64
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
65
66
        $tuples = [];
67
68
        return new static($tuples);
69
    }
70
71
72
    /**
73
     * Convert this SPKIData to XML.
74
     *
75
     * @param \DOMElement|null $parent The element we should append this SPKIData to.
76
     * @return \DOMElement
77
     */
78
    public function toXML(?DOMElement $parent = null): DOMElement
79
    {
80
        $e = $this->instantiateParentElement($parent);
81
82
        foreach ($this->getTuples() as $tuple) {
83
            list($spkisExp, $other) = $tuple;
84
85
            $spkisExp->toXML($e);
86
            $other?->toXML($e);
87
        }
88
89
        return $e;
90
    }
91
}
92