A PHP library that extends gosuperscript/axiom with support for Interval types, providing type-safe interval handling and operator overloading for schema validation.
- Interval Type: Transform and validate interval values in your schemas
- Operator Overloading: Compare intervals with numeric values using standard comparison operators (
>,<,>=,<=) - Type Safety: Built with PHP 8.4+ strict types
- Format Support: Parse intervals from string notation (e.g.,
[1,2],(1,2)) - Comparison: Compare intervals for equality
- PHP ^8.4
- ext-intl
- gosuperscript/axiom
- superscript/interval ^1.0.4
Install via Composer:
composer require gosuperscript/axiom-intervalThe IntervalType class provides type transformation, comparison, and formatting for interval values:
use Superscript\Axiom\Interval\Types\IntervalType;
use Superscript\Interval\Interval;
use Superscript\Interval\IntervalNotation;
use Brick\Math\BigNumber;
$type = new IntervalType();
// Transform from string
$result = $type->transform('[1,2]');
$interval = $result->unwrap()->unwrap();
// Transform from Interval object
$interval = new Interval(
BigNumber::of(1),
BigNumber::of(2),
IntervalNotation::Closed
);
$result = $type->transform($interval);
// Compare two intervals
$a = $type->transform('[1,2]')->unwrap()->unwrap();
$b = $type->transform('[1,2]')->unwrap()->unwrap();
$isEqual = $type->compare($a, $b); // true
// Format interval back to string
$formatted = $type->format($interval); // "[1,2]"Intervals can be specified using standard mathematical notation:
[1,2]- Closed interval (includes both endpoints)(1,2)- Open interval (excludes both endpoints)[1,2)- Half-open interval (includes left, excludes right)(1,2]- Half-open interval (excludes left, includes right)
The IntervalOverloader class enables comparison operations between intervals and numeric values:
use Superscript\Axiom\Interval\Operators\IntervalOverloader;
use Superscript\Interval\Interval;
$overloader = new IntervalOverloader();
$interval = Interval::fromString('[2,3]');
// Check if operator is supported
$supports = $overloader->supportsOverloading($interval, 1, '>'); // true
// Evaluate comparisons
$overloader->evaluate($interval, 1, '>'); // true (interval is greater than 1)
$overloader->evaluate($interval, 2, '>='); // true (interval is >= 2)
$overloader->evaluate($interval, 3, '<='); // true (interval is <= 3)
$overloader->evaluate($interval, 4, '<'); // true (interval is less than 4)>- Greater than>=- Greater than or equal to<- Less than<=- Less than or equal to
Run the full test suite:
composer testOr run individual test suites:
# Type checking with PHPStan
composer test:types
# Unit tests with PHPUnit (requires 100% code coverage)
composer test:unit
# Mutation testing with Infection
composer test:infectionThis project uses Laravel Pint for code formatting:
vendor/bin/pintThe project includes Docker configuration for development:
docker-compose up -dThis project is licensed under the MIT License - see the LICENSE file for details.
- Built on superscript/interval
- Extends gosuperscript/axiom