From 75eb9dad1c7778b025bc658f5cec2d6254dee7dd Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 29 Oct 2024 21:53:24 +0100 Subject: [PATCH] Fix: properly deal with default value --- src/XML/shibmd/Scope.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/XML/shibmd/Scope.php b/src/XML/shibmd/Scope.php index a2e817549..9fcdd71bb 100644 --- a/src/XML/shibmd/Scope.php +++ b/src/XML/shibmd/Scope.php @@ -24,11 +24,11 @@ final class Scope extends AbstractShibmdElement * Create a Scope. * * @param string $scope - * @param bool $regexp + * @param bool|null $regexp */ public function __construct( string $scope, - protected bool $regexp = false, + protected ?bool $regexp = false, ) { $this->setContent($scope); } @@ -50,9 +50,9 @@ protected function validateContent(string $content): void /** * Collect the value of the regexp-property * - * @return bool + * @return bool|null */ - public function isRegexpScope(): bool + public function isRegexpScope(): ?bool { return $this->regexp; } @@ -73,7 +73,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->namespaceURI, Scope::NS, InvalidDOMElementException::class); $scope = $xml->textContent; - $regexp = self::getOptionalBooleanAttribute($xml, 'regexp', false); + $regexp = self::getOptionalBooleanAttribute($xml, 'regexp', null); return new static($scope, $regexp); } @@ -89,7 +89,10 @@ public function toXML(DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); $e->textContent = $this->getContent(); - $e->setAttribute('regexp', $this->isRegexpScope() ? 'true' : 'false'); + + if ($this->isRegexpScope() !== null) { + $e->setAttribute('regexp', $this->isRegexpScope() ? 'true' : 'false'); + } return $e; }