Skip to content

Commit

Permalink
introduce loadMinFromNode method
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed Jan 12, 2024
1 parent 47866e8 commit 9490f3b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/SchemaReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,9 @@ private static function maybeSetAbstract(InterfaceSetAbstract $ref, \DOMElement

private function loadSequence(ElementContainer $elementContainer, \DOMElement $node, ?int $max = null, ?int $min = null): void
{
$min = $this->loadMinFromNode($node, $min);
$max = $this->loadMaxFromNode($node, $max);

$min =
(
null === $min
&& !$node->hasAttribute('minOccurs')
)
? null
: (int) max((int) $min, $node->getAttribute('minOccurs'));

self::againstDOMNodeList(
$node,
function (\DOMElement $node, \DOMElement $childNode) use ($elementContainer, $max, $min): void {
Expand All @@ -402,11 +395,22 @@ function (\DOMElement $node, \DOMElement $childNode) use ($elementContainer, $ma
);
}

private function loadMaxFromNode(\DOMElement $node, ?int $max): ?int
private function loadMinFromNode(\DOMElement $node, ?int $min): ?int
{
if (null === $min && !$node->hasAttribute('minOccurs')) {
return null;
}

$minOccurs = intval($node->getAttribute('minOccurs'));

return max($min, $minOccurs);
}

private function loadMaxFromNode(\DOMElement $node, ?int $max): ?int
{
$maxOccurs = $node->getAttribute('maxOccurs');

if ('unbounded' === $maxOccurs && null === $max) {
if (null === $max && 'unbounded' === $maxOccurs) {
return null;
}

Expand Down

0 comments on commit 9490f3b

Please sign in to comment.