diff --git a/src/Interval.php b/src/Interval.php index fbff5b7..48b322c 100644 --- a/src/Interval.php +++ b/src/Interval.php @@ -34,12 +34,12 @@ public static function fromString(string $interval): static $leftEndpoint = $matches['leftEndpoint'] ?? null; $rightEndpoint = $matches['rightEndpoint'] ?? null; - if (empty($leftEndpoint)) { + if (! $leftEndpoint && $leftEndpoint !== '0') { Assert::eq($openingSymbol, '(', 'Left endpoint must be defined when left side is closed.'); $leftEndpoint = PHP_INT_MIN; } - if (empty($rightEndpoint)) { + if (! $rightEndpoint && $rightEndpoint !== '0') { Assert::eq($closingSymbol, ')', 'Right endpoint must be defined when right side is closed.'); $rightEndpoint = PHP_INT_MAX; } diff --git a/tests/IntervalTest.php b/tests/IntervalTest.php index 2bd3ad6..4bb7cbc 100644 --- a/tests/IntervalTest.php +++ b/tests/IntervalTest.php @@ -36,6 +36,8 @@ public static function validCases(): array ['(,)', PHP_INT_MIN, PHP_INT_MAX, IntervalNotation::Open], ['[1,2)', 1, 2, IntervalNotation::RightOpen], ['(1,2]', 1, 2, IntervalNotation::LeftOpen], + ['[0,1)', 0, 1, IntervalNotation::RightOpen], + ['[-1,0]', -1, 0, IntervalNotation::Closed], ]; }