Manifest::getId()   A
last analyzed

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\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...
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Type\IDValue;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSchema\Type\IDValue 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
use SimpleSAML\XMLSecurity\Assert\Assert;
15
16
use function strval;
17
18
/**
19
 * Class representing a ds:Manifest element.
20
 *
21
 * @package simplesamlphp/xml-security
22
 */
23
final class Manifest extends AbstractDsElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement 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 ds:Manifest
30
     *
31
     * @param \SimpleSAML\XMLSecurity\XML\ds\Reference[] $references
32
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
33
     */
34
    public function __construct(
35
        protected array $references,
36
        protected ?IDValue $Id = null,
37
    ) {
38
        Assert::maxCount($references, C::UNBOUNDED_LIMIT);
39
        Assert::allIsInstanceOf($references, Reference::class);
40
    }
41
42
43
    /**
44
     * @return \SimpleSAML\XMLSecurity\XML\ds\Reference[]
45
     */
46
    public function getReferences(): array
47
    {
48
        return $this->references;
49
    }
50
51
52
    /**
53
     * @return \SimpleSAML\XMLSchema\Type\IDValue|null
54
     */
55
    public function getId(): ?IDValue
56
    {
57
        return $this->Id;
58
    }
59
60
61
    /**
62
     * Convert XML into a Manifest element
63
     *
64
     * @param \DOMElement $xml The XML element we should load
65
     *
66
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
67
     *   If the qualified name of the supplied element is wrong
68
     */
69
    public static function fromXML(DOMElement $xml): static
70
    {
71
        Assert::same($xml->localName, 'Manifest', InvalidDOMElementException::class);
72
        Assert::same($xml->namespaceURI, Manifest::NS, InvalidDOMElementException::class);
73
74
        $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null);
75
76
        $references = Reference::getChildrenOfClass($xml);
77
        Assert::minCount(
78
            $references,
79
            1,
80
            'A <ds:Manifest> must contain at least one <ds:Reference>.',
81
            MissingElementException::class,
82
        );
83
84
        return new static(
85
            $references,
86
            $Id,
87
        );
88
    }
89
90
91
    /**
92
     * Convert this Manifest element to XML.
93
     *
94
     * @param \DOMElement|null $parent The element we should append this Manifest element to.
95
     */
96
    public function toXML(?DOMElement $parent = null): DOMElement
97
    {
98
        $e = $this->instantiateParentElement($parent);
99
100
        if ($this->getId() !== null) {
101
            $e->setAttribute('Id', strval($this->getId()));
102
        }
103
104
        foreach ($this->getReferences() as $reference) {
105
            $reference->toXML($e);
106
        }
107
108
        return $e;
109
    }
110
}
111