PHPackages                             superscript/interval - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. superscript/interval

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

superscript/interval
====================

1.0.4(11mo ago)128.0k↑65.9%[1 issues](https://github.com/gosuperscript/interval/issues)4MITPHPPHP ^8.3CI passing

Since Mar 28Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/gosuperscript/interval)[ Packagist](https://packagist.org/packages/superscript/interval)[ RSS](/packages/superscript-interval/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (8)Used By (4)

Interval Library
================

[](#interval-library)

A PHP library for working with mathematical intervals. It provides an elegant way to create, compare, and work with intervals using standard mathematical notation.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require superscript/interval
```

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Usage
-----

[](#usage)

### Creating Intervals

[](#creating-intervals)

You can create intervals from string notation:

```
use Superscript\Interval\Interval;

// Create from string notation
$interval = Interval::fromString('[1,5]');  // Closed interval
$interval = Interval::fromString('(1,5)');  // Open interval
$interval = Interval::fromString('[1,5)');  // Right-open interval
$interval = Interval::fromString('(1,5]');  // Left-open interval
$interval = Interval::fromString('[1,)');  // Left-bounded interval (infinite upper bound)
$interval = Interval::fromString('(,1]');  // Right-bounded interval (infinite lower bound)
```

### Interval Notation

[](#interval-notation)

The library supports four types of interval notation:

- `[a,b]` - **Closed interval**: includes both endpoints `a` and `b`. Example: `[1,5]` includes all numbers from 1 to 5, including 1 and 5.
- `(a,b)` - **Open interval**: excludes both endpoints `a` and `b`. Example: `(1,5)` includes all numbers greater than 1 and less than 5, but not 1 or 5 themselves.
- `[a,b)` - **Right-open interval**: includes `a` but not `b`. Example: `[1,5)` includes 1 and all values up to (but not including) 5.
- `(a,b]` - **Left-open interval**: excludes `a` but includes `b`. Example: `(1,5]` includes all values greater than 1 up to and including 5.

The inclusion or exclusion of the endpoints determines how comparisons behave. For example, if an interval is `(1,5)`, calling `$interval->isGreaterThan(1)` will return `true` because 1 is not part of the interval. However, if the interval is `[1,5]`, then `$interval->isGreaterThanOrEqualTo(1)` will return `true` since 1 is included.

Understanding this notation is crucial for interpreting comparison behavior correctly.

The library also supports unbounded intervals using empty endpoints. These are interpreted as extending to infinity:

- `[a,)` - Left-bounded interval: includes `a` and extends infinitely to the right.
- `(,b]` - Right-bounded interval: includes `b` and extends infinitely to the left.
- `(,)` - Fully unbounded interval: represents all real numbers.

Internally, unbounded sides are represented using `PHP_INT_MIN` or `PHP_INT_MAX`.

### Interval Comparisons

[](#interval-comparisons)

```
$interval = Interval::fromString('[2,5]');

$interval->isGreaterThan(1);      // true
$interval->isGreaterThanOrEqualTo(2);  // true
$interval->isLessThan(6);         // true
$interval->isLessThanOrEqualTo(5);     // true
```

Comparisons such as `$interval->isGreaterThan($value)` evaluate whether *all* values within the interval are greater than the given value. So `[2,5]` is greater than `1` (because every number from 2 to 5 is greater than 1), but not greater than `2` unless the interval is open on the left side (e.g., `(2,5)`).

Similarly, `$interval->isLessThan($value)` checks whether all values in the interval are less than the given value. `(1,5)` is less than `6`, but not less than `5` unless the interval excludes `5` (e.g., `(1,5)` or `[1,5)`.

This logic allows for precise control over numeric comparisons, especially when you want to reason about bounds inclusivity.

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

This includes:

- Static analysis (`composer test:types`)
- Unit tests with coverage (`composer test:unit`)
- Mutation testing (`composer test:infection`)

License
-------

[](#license)

MIT

About
-----

[](#about)

This package is developed and maintained by Superscript.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Total

4

Last Release

333d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9832602d5b04f09fa5bd162acbaf87b0e5c50ce9a96b970424e78a3830695eb1?d=identicon)[robertvansteen](/maintainers/robertvansteen)

---

Top Contributors

[![robertvansteen](https://avatars.githubusercontent.com/u/14931924?v=4)](https://github.com/robertvansteen "robertvansteen (17 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/superscript-interval/health.svg)

```
[![Health](https://phpackages.com/badges/superscript-interval/health.svg)](https://phpackages.com/packages/superscript-interval)
```

###  Alternatives

[phpdocumentor/reflection-docblock

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

9.4k722.2M1.2k](/packages/phpdocumentor-reflection-docblock)[brick/money

Money and currency library

1.9k37.9M102](/packages/brick-money)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

374468.4k51](/packages/flow-php-etl)[sylius/promotion

Flexible promotion management for PHP applications.

28477.8k9](/packages/sylius-promotion)[sylius/taxonomy

Taxonomies - categorization of domain models in PHP projects.

14435.6k10](/packages/sylius-taxonomy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
