RepublishRequest::toXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\emd;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Exception\ArrayValidationException;
10
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
11
use SimpleSAML\XML\ArrayizableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
16
17
use function array_pop;
18
19
/**
20
 * Class implementing RepublishRequest.
21
 *
22
 * @package simplesamlphp/saml2
23
 */
24
final class RepublishRequest extends AbstractEmdElement implements
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\emd\AbstractEmdElement 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...
25
    ArrayizableElementInterface,
26
    SchemaValidatableElementInterface
27
{
28
    use SchemaValidatableElementTrait;
29
30
31
    /**
32
     * @param \SimpleSAML\SAML2\XML\emd\RepublishTarget $republishTarget
33
     */
34
    public function __construct(
35
        protected RepublishTarget $republishTarget,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SAML2\XML\emd\RepublishTarget 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
    ) {
37
    }
38
39
40
    /**
41
     * Collect the value of the RepublishTarget-property
42
     *
43
     * @return \SimpleSAML\SAML2\XML\emd\RepublishTarget
44
     */
45
    public function getRepublishTarget(): RepublishTarget
46
    {
47
        return $this->republishTarget;
48
    }
49
50
51
    /**
52
     * Convert XML into a RepublishRequest
53
     *
54
     * @param \DOMElement $xml The XML element we should load
55
     *
56
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
57
     *   if the qualified name of the supplied element is wrong
58
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
59
     *   if the supplied element is missing one of the mandatory attributes
60
     */
61
    public static function fromXML(DOMElement $xml): static
62
    {
63
        Assert::same($xml->localName, 'RepublishRequest', InvalidDOMElementException::class);
64
        Assert::same($xml->namespaceURI, RepublishRequest::NS, InvalidDOMElementException::class);
65
66
        $republishTarget = RepublishTarget::getChildrenOfClass($xml);
67
        Assert::count(
68
            $republishTarget,
69
            1,
70
            'A RepublishRequest can contain exactly one RepublishTarget.',
71
            SchemaViolationException::class,
72
        );
73
74
        return new static(array_pop($republishTarget));
75
    }
76
77
78
    /**
79
     * Convert this element to XML.
80
     *
81
     * @param \DOMElement|null $parent The element we should append to.
82
     */
83
    public function toXML(?DOMElement $parent = null): DOMElement
84
    {
85
        $e = $this->instantiateParentElement($parent);
86
87
        $this->republishTarget->toXML($e);
88
89
        return $e;
90
    }
91
92
93
    /**
94
     * Create a class from an array
95
     *
96
     * @param array{'RepublishTarget': string} $data
97
     */
98
    public static function fromArray(array $data): static
99
    {
100
        Assert::keyExists($data, 'RepublishTarget', ArrayValidationException::class);
101
        Assert::string($data['RepublishTarget'], ArrayValidationException::class);
102
103
        return new static(
104
            new RepublishTarget(
105
                SAMLAnyURIValue::fromString($data['RepublishTarget']),
106
            ),
107
        );
108
    }
109
110
111
    /**
112
     * Create an array from this class
113
     *
114
     * @return array{'RepublishTarget': string}
115
     */
116
    public function toArray(): array
117
    {
118
        return ['RepublishTarget' => $this->getRepublishTarget()->getContent()->getValue()];
119
    }
120
}
121