Passed
Push — master ( ba473f...2d22c8 )
by Tim
02:22 queued 16s
created

RepublishRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 89
rs 10
wmc 6

6 Methods

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