Skip to content

Commit

Permalink
Fix: properly deal with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Oct 29, 2024
1 parent 0192117 commit 75eb9da
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/XML/shibmd/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 75eb9da

Please sign in to comment.