PHPackages                             joby/toolbox - 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. joby/toolbox

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

joby/toolbox
============

A lightweight collection of useful general purpose PHP tools with no dependencies. Committed to always at least having minimal dependencies.

v1.2.0(1mo ago)01.3kMITPHPPHP ~8.1CI passing

Since Aug 4Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/joby-lol/php-toolbox)[ Packagist](https://packagist.org/packages/joby/toolbox)[ RSS](/packages/joby-toolbox/feed)WikiDiscussions main Synced 1mo ago

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

Joby's PHP Toolbox
==================

[](#jobys-php-toolbox)

A lightweight collection of useful general purpose PHP tools with no dependencies. Committed to always at least having minimal dependencies.

URL-safe Base64
---------------

[](#url-safe-base64)

`Encoding` has functions for URL-safe base64 encoding. Simple implementation that replaces `+` and `/` with `-` and `_`, respectively. Also strips right padding `=` signs as they are not necessary for decoding.

```
use Joby\Toolbox\Strings\Encoding;

// encode a string or binary data
$encoded = Encoding::base64url_encode($your_data);

// decode it
$decoded = Encoding::base64_url_decode($encoded);
```

Array Tools
-----------

[](#array-tools)

The `ArrayFunctions` class provides enhanced array manipulation capabilities:

- **shift\_n**: Shifts multiple elements from the start of an array at once

    ```
    $array = [1, 2, 3, 4, 5];
    $shifted = ArrayFunctions::shift_n($array, 2); // Returns [1, 2]
    // $array is now [3, 4, 5]
    ```
- **pop\_n**: Pops multiple elements from the end of an array at once

    ```
    $array = [1, 2, 3, 4, 5];
    $popped = ArrayFunctions::pop_n($array, 2); // Returns [5, 4]
    // $array is now [1, 2, 3]
    ```
- **min/max**: Enhanced versions of PHP's min/max functions with special handling for null values

    ```
    $array = [1, 2, 3, null, 5];
    $min = ArrayFunctions::min($array); // Returns null (nulls are low by default)
    $min = ArrayFunctions::min($array, true); // Returns 1 (nulls are high)
    $max = ArrayFunctions::max($array); // Returns 5 (nulls are low by default)
    $max = ArrayFunctions::max($array, true); // Returns null (nulls are high)
    ```

Sorting Tools
-------------

[](#sorting-tools)

The sorting component provides flexible and powerful sorting capabilities:

### Sort Class

[](#sort-class)

Static interface for one-time sorting operations:

```
// Basic sorting
$data = [3, 1, 4, 1, 5, 9];
Sort::sort($data, fn ($a, $b) => $a  $b);

// Multi-criteria sorting (even numbers first, then by value)
$data = [3, 1, 4, 1, 5, 9];
Sort::sort($data, fn ($a, $b) => $a % 2  $b % 2, fn ($a, $b) => $a  $b);

// Reverse sorting
Sort::sort($data, Sort::reverse(fn ($a, $b) => $a  $b));

// Sorting objects by method results
Sort::sort($objects, Sort::compareMethods('getNumber'));

// Sorting objects by property values
Sort::sort($objects, Sort::compareProperties('itemName'));

// Sorting arrays by key values
Sort::sort($arrayOfArrays, Sort::compareArrayValues('name'));

// Sorting by callback results (e.g., string length)
Sort::sort($strings, Sort::compareCallbackResults(strlen(...)));
```

### Sorter Class

[](#sorter-class)

For reusable sorting operations:

```
// Create a sorter with multiple criteria
$sorter = new Sorter(
    fn ($a, $b) => $a->priority  $b->priority,
    fn ($a, $b) => $a->name  $b->name
);

// Sort multiple arrays with the same criteria
$sorter->sort($array1);
$sorter->sort($array2);
```

### Sortable Interface

[](#sortable-interface)

Objects can implement the `Sortable` interface to provide a default sorting value:

```
class MyClass implements Sortable {
    public function sortByValue(): string|int|float|bool {
        return $this->priority;
    }
}
```

Range Tools
-----------

[](#range-tools)

The Ranges component provides tools for working with ranges of values:

### AbstractRange

[](#abstractrange)

An abstract base class for implementing ranges with various value types:

- Boolean operations: `booleanAnd`, `booleanOr`, `booleanXor`, `booleanNot`
- Comparison methods: `equals`, `intersects`, `contains`, `adjacent`
- Boundary management: `setStart`, `setEnd`, `start`, `end`

```
// Example using IntegerRange implementation
$range1 = new IntegerRange(1, 5);
$range2 = new IntegerRange(3, 8);

// Intersection (AND)
$intersection = $range1->booleanAnd($range2); // Range from 3 to 5

// Union (OR)
$union = $range1->booleanOr($range2); // Collection with range from 1 to 8

// Exclusive OR
$xor = $range1->booleanXor($range2); // Collection with ranges 1-3 and 5-8
```

### RangeCollection

[](#rangecollection)

Manages collections of ranges with operations for merging and manipulation:

```
// Create a collection of ranges
$collection = RangeCollection::create($range1, $range2);

// Merge overlapping and adjacent ranges
$merged = $collection->mergeRanges();
```

### IntegerRange

[](#integerrange)

A concrete implementation of AbstractRange for integer values.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance89

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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 ~77 days

Total

4

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4e606aa41ebfd7d82c365c6dc4ec158fb1b0bfff5f8dcbfad4ab53e3092e6a6?d=identicon)[jobyone](/maintainers/jobyone)

---

Top Contributors

[![joby-lol](https://avatars.githubusercontent.com/u/856610?v=4)](https://github.com/joby-lol "joby-lol (43 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joby-toolbox/health.svg)

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

PHPackages © 2026

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