PHPackages                             harp-orm/range - 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. harp-orm/range

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

harp-orm/range
==============

An object representing 2 integer values

0.2.1(11y ago)1521BSD-3-ClausePHPPHP &gt;=5.4.0

Since Jul 17Pushed 11y ago2 watchersCompare

[ Source](https://github.com/harp-orm/range)[ Packagist](https://packagist.org/packages/harp-orm/range)[ RSS](/packages/harp-orm-range/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Range
=====

[](#range)

[![Build Status](https://camo.githubusercontent.com/3227ab8a65b306faabdcf2142a91d41bf2cacdd48fdbf43e112df2bea9127d33/68747470733a2f2f7472617669732d63692e6f72672f686172702d6f726d2f72616e67652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/harp-orm/range)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/80764674c28fbbabc691589bcc4e11d445fdf4d6e6f6af2dc12813329a190cb4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686172702d6f726d2f72616e67652f6261646765732f7175616c6974792d73636f72652e706e67)](https://scrutinizer-ci.com/g/harp-orm/range/)[![Code Coverage](https://camo.githubusercontent.com/7146e331275bab62b138412cab841b6fee13f6bdc555a4f78dd71b3a1803f969/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686172702d6f726d2f72616e67652f6261646765732f636f7665726167652e706e67)](https://scrutinizer-ci.com/g/harp-orm/range/)[![Latest Stable Version](https://camo.githubusercontent.com/438ec8574a86512ae33516a4bd52be41376e1dd128728e80048a29543e098668/68747470733a2f2f706f7365722e707567782e6f72672f686172702d6f726d2f72616e67652f762f737461626c652e706e67)](https://packagist.org/packages/harp-orm/range)

An object representing 2 integer values

Usage
-----

[](#usage)

This is a object representing two values - min and max, that can be stored string (as "first\_value|second\_value"). You can set / retrieve it as string or as an array like this:

```
$range = new Range(5, 10);

// Will return 5
echo $range->getMin();

// Will return 10
echo $range->getMax();

// It also implements ArrayAccess
echo $range[0]; // 5
echo $range[1]; // 10

$range[0] = 2;
$range[1] = 9;

// And you can convert it to a short string representation
// For example for storing in the DB
echo (string) $range; // 2|9
$newRange = Range::fromString('2|9');

// You can "add" ranges together
// This will add the min and the max values
$range = new Range(5, 10);
$range->add(new Range(3, 20));
echo $range; // 8|30

// You can get a human readable version with humanize method
$range = new Range(5, 10);
echo $range->humanize(); // 5 - 10

// This is also custumizable
$range = new Range(5, 10, '%s - / - %s');
echo $range->humanize(); // 5 - / - 10

// You can add a closure to further custumize this
$range = new Range(5, 10, function ($min, $max) {
    return $min.'..'.$max;
});
echo $range->humanize(); // 5..10
```

Aggregate Methods
-----------------

[](#aggregate-methods)

There are several methods for working with multiple ranges:

```
$range1 = new Range(5, 10);
$range2 = new Range(2, 8);
$range3 = new Range(9, 8);

// Sum adds all of the ranges together
$range = Range::sum([$range1, $range2, $range3], '%s - %s');
echo $range; // 16|26

// Get the maximum values for the first and second value
$range = Range::merge([$range1, $range2, $range3], '%s - %s');
echo $range; // 9|10
```

Using with models
-----------------

[](#using-with-models)

There is a trait that adds methods for working with ranges to a model. To persist the data, it adds the "days" property to the model.

```
use Harp\Harp\AbstractModel;
use Harp\Range\DaysRangeTrait;

class TestModel extends AbstractModel
{
    use DaysRangeTrait;

    public static function initialize($config)
    {
        DaysRangeTrait::initialize($config);
    }
}

$testModel = new TestModel();

// Will get you a Range object
$testModel->getDays();

$testModel->setDays(new Range(5, 10));

// Will return "5|10"
echo $testModel->days;
```

License
-------

[](#license)

Copyright (c) 2014, Clippings Ltd. Developed by Ivan Kerin

Under BSD-3-Clause license, read LICENSE file.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~13 days

Total

4

Last Release

4278d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/506129?v=4)[Harry Dobrev](/maintainers/hkdobrev)[@hkdobrev](https://github.com/hkdobrev)

---

Top Contributors

[![ivank](https://avatars.githubusercontent.com/u/4976?v=4)](https://github.com/ivank "ivank (9 commits)")

### Embed Badge

![Health badge](/badges/harp-orm-range/health.svg)

```
[![Health](https://phpackages.com/badges/harp-orm-range/health.svg)](https://phpackages.com/packages/harp-orm-range)
```

###  Alternatives

[scssphp/scssphp

scssphp is a compiler for SCSS written in PHP.

62827.7M220](/packages/scssphp-scssphp)[cloudstudio/resource-generator

Resource Generator for Laravel Nova

106136.1k1](/packages/cloudstudio-resource-generator)[mervick/material-design-icons

Google Material Design Icons For Using With Bootstrap

10191.4k7](/packages/mervick-material-design-icons)[midnite81/geolocation

A laravel package which wraps the IP Info DB and IP2Location Services

3624.1k](/packages/midnite81-geolocation)[dereuromark/cakephp-tags

Tags plugin for CakePHP

1660.2k1](/packages/dereuromark-cakephp-tags)[nlac/nlsclientscript

Yii ClientScript extension for prevent reloading javascript and merging/minfying resources

208.2k](/packages/nlac-nlsclientscript)

PHPackages © 2026

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