Skip to content

Commit

Permalink
Explicit nullable type
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 1, 2024
1 parent c7072b4 commit 4996379
Show file tree
Hide file tree
Showing 39 changed files with 130 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/XML/EncryptedElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function fromXML(DOMElement $xml): static
/**
* @inheritDoc
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$this->encryptedData->toXML($e);
Expand All @@ -196,7 +196,7 @@ public function toXML(DOMElement $parent = null): DOMElement
* @param \DOMElement|null $parent The element we should append to.
* @return \DOMElement
*/
abstract public function instantiateParentElement(DOMElement $parent = null): DOMElement;
abstract public function instantiateParentElement(?DOMElement $parent = null): DOMElement;


/**
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/AbstractKeyInfoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function getInfo(): array
* @param \DOMElement|null $parent The element we should append this KeyInfo to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
91 changes: 91 additions & 0 deletions src/XML/ds/AbstractSPKIDataType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\XML\ds;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\SerializableElementInterface;
use SimpleSAML\XML\XsNamespace as NS;
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;

/**
* Abstract class representing the SPKIDataType.
*
* @package simplesamlphp/xml-security
*/
abstract class AbstractSPKIDataType extends AbstractDsElement
{
/**
* Initialize a SPKIData element.
*
* @param array<\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, SimpleSAML\XML\SerializableElementInterface|null> $tuples
*/
final public function __construct(
protected array $tuples,
) {
Assert::allIsArray($tuples, SchemaViolationException::class);

foreach ($tuples as $tuple) {
list($spkisExp, $other) = $tuple;
Assert::instanceOf($spkisExp, SPKISexp::class, SchemaViolationException::class);
Assert::instanceOf($other, SerializableElementInterface::class, SchemaViolationException::class);
}
}


/**
* Collect the value of the SPKISexp-property
*
* @return array<\SimpleSAML\XMLSecurity\XML\ds\SPKISexp, SimpleSAML\XML\SerializableElementInterface|null>
*/
public function getTuples(): array
{
return $this->tuples;
}


/**
* Convert XML into a SPKIData
*
* @param \DOMElement $xml The XML element we should load
* @return static
*
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
* If the qualified name of the supplied element is wrong
*/
public static function fromXML(DOMElement $xml): static
{
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);

$tuples = [];

return new static($tuples);
}


/**
* Convert this SPKIData to XML.
*
* @param \DOMElement|null $parent The element we should append this SPKIData to.
* @return \DOMElement
*/
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

foreach ($this->getTuples() as $tuple) {
list($spkisExp, $other) = $tuple;

$spkisExp->toXML($e);
$other?->toXML($e);
}

return $e;
}
}
2 changes: 1 addition & 1 deletion src/XML/ds/CanonicalizationMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this KeyName element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Algorithm', $this->getAlgorithm());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/DigestMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this DigestMethod element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Algorithm', $this->getAlgorithm());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/DsObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this ds:Object element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/KeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this KeyValue element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this Manifest element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/RSAKeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this RSAKeyValue element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this Reference element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
if ($this->getId() !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/RetrievalMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this RetrievalMethod element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('URI', $this->getURI());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this Signature element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/SignatureMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this SignatureMethod element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Algorithm', $this->getAlgorithm());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/SignatureProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this SignatureProperties element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/SignatureProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this SignatureProperty element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Target', $this->getTarget());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/SignatureValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this SignatureValue element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->textContent = $this->getContent();
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/SignedInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this SignedInfo element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this Transform element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/Transforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this Transforms element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/X509Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this X509Data element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/X509IssuerSerial.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this X509IssuerSerial element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/X509SerialNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this X509SerialNumber element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->textContent = $this->getContent();
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ds/XPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function fromXML(DOMElement $xml): static
* @param DOMElement|null $parent
* @return DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->textContent = $this->getExpression();
Expand Down
2 changes: 1 addition & 1 deletion src/XML/dsig11/KeyInfoReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this KeyInfoReference element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('URI', $this->getURI());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/dsig11/X509Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this X509Digest element to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->textContent = $this->getContent();
Expand Down
2 changes: 1 addition & 1 deletion src/XML/ec/InclusiveNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this InclusiveNamespaces to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractAgreementMethodType.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this AgreementMethod to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Algorithm', $this->getAlgorithm());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractDHKeyValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this DHKeyValue to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractEncryptedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function getType(): ?string
/**
* @inheritDoc
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractEncryptionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function fromXML(DOMElement $xml): static
* @param \DOMElement|null $parent The element we should append this EncryptionMethod to.
* @return \DOMElement
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('Algorithm', $this->getAlgorithm());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractEncryptionPropertiesType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function fromXML(DOMElement $xml): static
/**
* @inheritDoc
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractEncryptionPropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function fromXML(DOMElement $xml): static
/**
* @inheritDoc
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/AbstractReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function fromXML(DOMElement $xml): static
/**
* @inheritDoc
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);
$e->setAttribute('URI', $this->getUri());
Expand Down
2 changes: 1 addition & 1 deletion src/XML/xenc/CipherData.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function fromXML(DOMElement $xml): static
/**
* @inheritDoc
*/
public function toXML(DOMElement $parent = null): DOMElement
public function toXML(?DOMElement $parent = null): DOMElement
{
$e = $this->instantiateParentElement($parent);

Expand Down
Loading

0 comments on commit 4996379

Please sign in to comment.