AbstractDHKeyValueType   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
eloc 45
c 1
b 0
f 0
dl 0
loc 167
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 31 1
A getQ() 0 3 1
A __construct() 0 18 6
A getPgenCounter() 0 3 1
A getPublic() 0 3 1
A getGenerator() 0 3 1
A getP() 0 3 1
A getSeed() 0 3 1
A toXML() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
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\Exception\SchemaViolationException;
14
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
15
16
use function array_pop;
17
18
/**
19
 * A class implementing the xenc:AbstractDHKeyValueType element.
20
 *
21
 * @package simplesamlphp/xml-security
22
 */
23
abstract class AbstractDHKeyValueType extends AbstractXencElement implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\X...enc\AbstractXencElement 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
     * DHKeyValueType constructor.
30
     *
31
     * @param \SimpleSAML\XMLSecurity\XML\xenc\XencPublic $xencPublic
32
     * @param \SimpleSAML\XMLSecurity\XML\xenc\P|null $p
33
     * @param \SimpleSAML\XMLSecurity\XML\xenc\Q|null $q
34
     * @param \SimpleSAML\XMLSecurity\XML\xenc\Generator|null $generator
35
     * @param \SimpleSAML\XMLSecurity\XML\xenc\Seed|null $seed
36
     * @param \SimpleSAML\XMLSecurity\XML\xenc\PgenCounter|null $pgenCounter
37
     */
38
    final public function __construct(
39
        protected XencPublic $xencPublic,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\xenc\XencPublic 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...
40
        protected ?P $p = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\xenc\P 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...
41
        protected ?Q $q = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\xenc\Q 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...
42
        protected ?Generator $generator = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\xenc\Generator was not found. Did you mean Generator? If so, make sure to prefix the type with \.
Loading history...
43
        protected ?Seed $seed = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\xenc\Seed 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...
44
        protected ?PgenCounter $pgenCounter = null,
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\xenc\PgenCounter 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...
45
    ) {
46
        if ($p !== null || $q !== null || $generator !== null) {
47
            Assert::allNotNull([$p, $q, $generator], SchemaViolationException::class);
48
        } else {
49
            Assert::allNull([$p, $q, $generator], SchemaViolationException::class);
50
        }
51
52
        if ($seed !== null || $pgenCounter !== null) {
53
            Assert::allNotNull([$seed, $pgenCounter], SchemaViolationException::class);
54
        } else {
55
            Assert::allNull([$seed, $pgenCounter], SchemaViolationException::class);
56
        }
57
    }
58
59
60
    /**
61
     * Get the Public.
62
     *
63
     * @return \SimpleSAML\XMLSecurity\XML\xenc\XencPublic
64
     */
65
    public function getPublic(): XencPublic
66
    {
67
        return $this->xencPublic;
68
    }
69
70
71
    /**
72
     * Get the P.
73
     *
74
     * @return \SimpleSAML\XMLSecurity\XML\xenc\P|null
75
     */
76
    public function getP(): ?P
77
    {
78
        return $this->p;
79
    }
80
81
82
    /**
83
     * Get the Q.
84
     *
85
     * @return \SimpleSAML\XMLSecurity\XML\xenc\Q|null
86
     */
87
    public function getQ(): ?Q
88
    {
89
        return $this->q;
90
    }
91
92
93
    /**
94
     * Get the Generator.
95
     *
96
     * @return \SimpleSAML\XMLSecurity\XML\xenc\Generator|null
97
     */
98
    public function getGenerator(): ?Generator
99
    {
100
        return $this->generator;
101
    }
102
103
104
    /**
105
     * Get the Seed.
106
     *
107
     * @return \SimpleSAML\XMLSecurity\XML\xenc\Seed|null
108
     */
109
    public function getSeed(): ?Seed
110
    {
111
        return $this->seed;
112
    }
113
114
115
    /**
116
     * Get the PgenCounter.
117
     *
118
     * @return \SimpleSAML\XMLSecurity\XML\xenc\PgenCounter|null
119
     */
120
    public function getPgenCounter(): ?PgenCounter
121
    {
122
        return $this->pgenCounter;
123
    }
124
125
126
    /**
127
     * Initialize an DHKeyValue object from an existing XML.
128
     *
129
     * @param \DOMElement $xml
130
     *
131
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
132
     *   if the qualified name of the supplied element is wrong
133
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
134
     *   if the supplied element is missing one of the mandatory attributes
135
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
136
     *   if too many child-elements of a type are specified
137
     */
138
    public static function fromXML(DOMElement $xml): static
139
    {
140
        Assert::same($xml->localName, 'DHKeyValue', InvalidDOMElementException::class);
141
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
142
143
        $xencPublic = XencPublic::getChildrenOfClass($xml);
144
        Assert::minCount($xencPublic, 1, MissingElementException::class);
145
        Assert::maxCount($xencPublic, 1, TooManyElementsException::class);
146
147
        $p = P::getChildrenOfClass($xml);
148
        Assert::maxCount($p, 1, TooManyElementsException::class);
149
150
        $q = Q::getChildrenOfClass($xml);
151
        Assert::maxCount($q, 1, TooManyElementsException::class);
152
153
        $generator = Generator::getChildrenOfClass($xml);
154
        Assert::maxCount($generator, 1, TooManyElementsException::class);
155
156
        $seed = Seed::getChildrenOfClass($xml);
157
        Assert::maxCount($seed, 1, TooManyElementsException::class);
158
159
        $pgenCounter = PgenCounter::getChildrenOfClass($xml);
160
        Assert::maxCount($pgenCounter, 1, TooManyElementsException::class);
161
162
        return new static(
163
            array_pop($xencPublic),
164
            array_pop($p),
165
            array_pop($q),
166
            array_pop($generator),
167
            array_pop($seed),
168
            array_pop($pgenCounter),
169
        );
170
    }
171
172
173
    /**
174
     * Convert this DHKeyValue object to XML.
175
     *
176
     * @param \DOMElement|null $parent The element we should append this DHKeyValue to.
177
     */
178
    public function toXML(?DOMElement $parent = null): DOMElement
179
    {
180
        $e = $this->instantiateParentElement($parent);
181
182
        $this->getP()?->toXML($e);
183
        $this->getQ()?->toXML($e);
184
        $this->getGenerator()?->toXML($e);
185
        $this->getPublic()->toXML($e);
186
        $this->getSeed()?->toXML($e);
187
        $this->getPgenCounter()?->toXML($e);
188
189
        return $e;
190
    }
191
}
192