Skip to content

Commit 4996379

Browse files
committed
Explicit nullable type
1 parent c7072b4 commit 4996379

39 files changed

+130
-39
lines changed

src/XML/EncryptedElementTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static function fromXML(DOMElement $xml): static
179179
/**
180180
* @inheritDoc
181181
*/
182-
public function toXML(DOMElement $parent = null): DOMElement
182+
public function toXML(?DOMElement $parent = null): DOMElement
183183
{
184184
$e = $this->instantiateParentElement($parent);
185185
$this->encryptedData->toXML($e);
@@ -196,7 +196,7 @@ public function toXML(DOMElement $parent = null): DOMElement
196196
* @param \DOMElement|null $parent The element we should append to.
197197
* @return \DOMElement
198198
*/
199-
abstract public function instantiateParentElement(DOMElement $parent = null): DOMElement;
199+
abstract public function instantiateParentElement(?DOMElement $parent = null): DOMElement;
200200

201201

202202
/**

src/XML/ds/AbstractKeyInfoType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function getInfo(): array
100100
* @param \DOMElement|null $parent The element we should append this KeyInfo to.
101101
* @return \DOMElement
102102
*/
103-
public function toXML(DOMElement $parent = null): DOMElement
103+
public function toXML(?DOMElement $parent = null): DOMElement
104104
{
105105
$e = $this->instantiateParentElement($parent);
106106

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\ds;
6+
7+
use DOMElement;
8+
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10+
use SimpleSAML\XML\Exception\SchemaViolationException;
11+
use SimpleSAML\XML\Exception\TooManyElementsException;
12+
use SimpleSAML\XML\SerializableElementInterface;
13+
use SimpleSAML\XML\XsNamespace as NS;
14+
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
15+
16+
/**
17+
* Abstract class representing the SPKIDataType.
18+
*
19+
* @package simplesamlphp/xml-security
20+
*/
21+
abstract class AbstractSPKIDataType extends AbstractDsElement
22+
{
23+
/**
24+
* Initialize a SPKIData element.
25+
*
26+
* @param array<\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, SimpleSAML\XML\SerializableElementInterface|null> $tuples
27+
*/
28+
final public function __construct(
29+
protected array $tuples,
30+
) {
31+
Assert::allIsArray($tuples, SchemaViolationException::class);
32+
33+
foreach ($tuples as $tuple) {
34+
list($spkisExp, $other) = $tuple;
35+
Assert::instanceOf($spkisExp, SPKISexp::class, SchemaViolationException::class);
36+
Assert::instanceOf($other, SerializableElementInterface::class, SchemaViolationException::class);
37+
}
38+
}
39+
40+
41+
/**
42+
* Collect the value of the SPKISexp-property
43+
*
44+
* @return array<\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, SimpleSAML\XML\SerializableElementInterface|null>
45+
*/
46+
public function getTuples(): array
47+
{
48+
return $this->tuples;
49+
}
50+
51+
52+
/**
53+
* Convert XML into a SPKIData
54+
*
55+
* @param \DOMElement $xml The XML element we should load
56+
* @return static
57+
*
58+
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
59+
* If the qualified name of the supplied element is wrong
60+
*/
61+
public static function fromXML(DOMElement $xml): static
62+
{
63+
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
64+
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
65+
66+
$tuples = [];
67+
68+
return new static($tuples);
69+
}
70+
71+
72+
/**
73+
* Convert this SPKIData to XML.
74+
*
75+
* @param \DOMElement|null $parent The element we should append this SPKIData to.
76+
* @return \DOMElement
77+
*/
78+
public function toXML(?DOMElement $parent = null): DOMElement
79+
{
80+
$e = $this->instantiateParentElement($parent);
81+
82+
foreach ($this->getTuples() as $tuple) {
83+
list($spkisExp, $other) = $tuple;
84+
85+
$spkisExp->toXML($e);
86+
$other?->toXML($e);
87+
}
88+
89+
return $e;
90+
}
91+
}

src/XML/ds/CanonicalizationMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function fromXML(DOMElement $xml): static
7878
* @param \DOMElement|null $parent The element we should append this KeyName element to.
7979
* @return \DOMElement
8080
*/
81-
public function toXML(DOMElement $parent = null): DOMElement
81+
public function toXML(?DOMElement $parent = null): DOMElement
8282
{
8383
$e = $this->instantiateParentElement($parent);
8484
$e->setAttribute('Algorithm', $this->getAlgorithm());

src/XML/ds/DigestMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static function fromXML(DOMElement $xml): static
8484
* @param \DOMElement|null $parent The element we should append this DigestMethod element to.
8585
* @return \DOMElement
8686
*/
87-
public function toXML(DOMElement $parent = null): DOMElement
87+
public function toXML(?DOMElement $parent = null): DOMElement
8888
{
8989
$e = $this->instantiateParentElement($parent);
9090
$e->setAttribute('Algorithm', $this->getAlgorithm());

src/XML/ds/DsObject.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static function fromXML(DOMElement $xml): static
123123
* @param \DOMElement|null $parent The element we should append this ds:Object element to.
124124
* @return \DOMElement
125125
*/
126-
public function toXML(DOMElement $parent = null): DOMElement
126+
public function toXML(?DOMElement $parent = null): DOMElement
127127
{
128128
$e = $this->instantiateParentElement($parent);
129129

src/XML/ds/KeyValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static function fromXML(DOMElement $xml): static
100100
* @param \DOMElement|null $parent The element we should append this KeyValue element to.
101101
* @return \DOMElement
102102
*/
103-
public function toXML(DOMElement $parent = null): DOMElement
103+
public function toXML(?DOMElement $parent = null): DOMElement
104104
{
105105
$e = $this->instantiateParentElement($parent);
106106

src/XML/ds/Manifest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static function fromXML(DOMElement $xml): static
8888
* @param \DOMElement|null $parent The element we should append this Manifest element to.
8989
* @return \DOMElement
9090
*/
91-
public function toXML(DOMElement $parent = null): DOMElement
91+
public function toXML(?DOMElement $parent = null): DOMElement
9292
{
9393
$e = $this->instantiateParentElement($parent);
9494

src/XML/ds/RSAKeyValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function fromXML(DOMElement $xml): static
104104
* @param \DOMElement|null $parent The element we should append this RSAKeyValue element to.
105105
* @return \DOMElement
106106
*/
107-
public function toXML(DOMElement $parent = null): DOMElement
107+
public function toXML(?DOMElement $parent = null): DOMElement
108108
{
109109
$e = $this->instantiateParentElement($parent);
110110

src/XML/ds/Reference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public static function fromXML(DOMElement $xml): static
167167
* @param \DOMElement|null $parent The element we should append this Reference element to.
168168
* @return \DOMElement
169169
*/
170-
public function toXML(DOMElement $parent = null): DOMElement
170+
public function toXML(?DOMElement $parent = null): DOMElement
171171
{
172172
$e = $this->instantiateParentElement($parent);
173173
if ($this->getId() !== null) {

0 commit comments

Comments
 (0)