PublicationPath::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\mdrpi;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Exception\ArrayValidationException;
10
use SimpleSAML\XML\ArrayizableElementInterface;
11
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...
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
16
/**
17
 * Class for handling the mdrpi:PublicationPath element.
18
 *
19
 * @link: http://docs.oasis-open.org/security/saml/Post2.0/saml-metadata-rpi/v1.0/saml-metadata-rpi-v1.0.pdf
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
final class PublicationPath extends AbstractMdrpiElement implements
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\mdrpi\AbstractMdrpiElement 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
    ArrayizableElementInterface,
25
    SchemaValidatableElementInterface
26
{
27
    use SchemaValidatableElementTrait;
28
29
30
    /**
31
     * Create/parse a mdrpi:PublicationPath element.
32
     *
33
     * @param \SimpleSAML\SAML2\XML\mdrpi\Publication[] $publication
34
     */
35
    public function __construct(
36
        protected array $publication = [],
37
    ) {
38
        Assert::maxCount($publication, C::UNBOUNDED_LIMIT);
39
        Assert::allIsInstanceOf($publication, Publication::class);
40
    }
41
42
43
    /**
44
     * Collect the value of the Publication-property
45
     *
46
     * @return \SimpleSAML\SAML2\XML\mdrpi\Publication[]
47
     */
48
    public function getPublication(): array
49
    {
50
        return $this->publication;
51
    }
52
53
54
    /**
55
     * Test if an object, at the state it's in, would produce an empty XML-element
56
     */
57
    public function isEmptyElement(): bool
58
    {
59
        return empty($this->publication);
60
    }
61
62
63
    /**
64
     * Convert XML into a PublicationPath
65
     *
66
     * @param \DOMElement $xml The XML element we should load
67
     * @return static
68
     *
69
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
70
     *   if the qualified name of the supplied element is wrong
71
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
72
     *   if the supplied element is missing one of the mandatory attributes
73
     */
74
    public static function fromXML(DOMElement $xml): static
75
    {
76
        Assert::same($xml->localName, 'PublicationPath', InvalidDOMElementException::class);
77
        Assert::same($xml->namespaceURI, PublicationPath::NS, InvalidDOMElementException::class);
78
79
        $Publication = Publication::getChildrenOfClass($xml);
80
81
        return new static($Publication);
82
    }
83
84
85
    /**
86
     * Convert this element to XML.
87
     */
88
    public function toXML(?DOMElement $parent = null): DOMElement
89
    {
90
        $e = $this->instantiateParentElement($parent);
91
92
        foreach ($this->getPublication() as $pub) {
93
            $pub->toXML($e);
94
        }
95
96
        return $e;
97
    }
98
99
100
    /**
101
     * Create a class from an array
102
     *
103
     * @param array{array} $data
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{array} at position 2 could not be parsed: Expected ':' at position 2, but found 'array'.
Loading history...
104
     */
105
    public static function fromArray(array $data): static
106
    {
107
        Assert::allIsArray($data, ArrayValidationException::class);
108
109
        $publication = [];
110
        foreach ($data as $p) {
111
            $publication[] = Publication::fromArray($p);
112
        }
113
114
        return new static($publication);
115
    }
116
117
118
    /**
119
     * Create an array from this class
120
     *
121
     * @return array{array}
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{array} at position 2 could not be parsed: Expected ':' at position 2, but found 'array'.
Loading history...
122
     */
123
    public function toArray(): array
124
    {
125
        $data = [];
126
        foreach ($this->getPublication() as $p) {
127
            $data[] = $p->toArray();
128
        }
129
130
        return $data;
131
    }
132
}
133