gosuperscript/schema-interval

There is no license information available for the latest version (v0.1.0) of this package.

A PHP library that extends gosuperscript/schema with support for Interval types, providing type-safe interval handling and operator overloading for schema validation

Installs: 15

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 1

pkg:composer/gosuperscript/schema-interval

v0.1.0 2025-11-10 12:39 UTC

README

A PHP library that extends gosuperscript/schema with support for Interval types, providing type-safe interval handling and operator overloading for schema validation.

Features

  • 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

Requirements

Installation

Install via Composer:

composer require gosuperscript/axiom-interval

Usage

Interval Type

The IntervalType class provides type transformation, comparison, and formatting for interval values:

use Superscript\Schema\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]"

Interval Notation

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)

Operator Overloading

The IntervalOverloader class enables comparison operations between intervals and numeric values:

use Superscript\Schema\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)

Supported Operators

  • > - Greater than
  • >= - Greater than or equal to
  • < - Less than
  • <= - Less than or equal to

Development

Testing

Run the full test suite:

composer test

Or 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:infection

Code Style

This project uses Laravel Pint for code formatting:

vendor/bin/pint

Docker Support

The project includes Docker configuration for development:

docker-compose up -d

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits