PHPackages                             toobo/hop - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. toobo/hop

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

toobo/hop
=========

Higher-order functional predicates.

2.0.0(3y ago)5647MITPHPPHP &gt;=8.0

Since Apr 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Toobo/Hop)[ Packagist](https://packagist.org/packages/toobo/hop)[ Docs](https://github.com/Toobo/Hop)[ RSS](/packages/toobo-hop/feed)WikiDiscussions master Synced 2mo ago

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

Hop
===

[](#hop)

---

[![license](https://camo.githubusercontent.com/962b2fe0e81d976927218dc8e47a1420b1889e102046a26fdb14d11730ee9fd9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f6f626f2f486f702e7376673f7374796c653d666c61742d737175617265)](http://opensource.org/licenses/MIT)[![Quality Assurance](https://github.com/Toobo/Hop/actions/workflows/qa.yml/badge.svg)](https://github.com/Toobo/Hop/actions/workflows/qa.yml)[![codecov.io](https://camo.githubusercontent.com/55611aeb27250db9e6c94e952003cc7528d57809a753fb7dc97ba61c8574e771/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f546f6f626f2f486f702e7376673f7374796c653d666c61742d737175617265)](http://codecov.io/github/Toobo/Hop?branch=master)[![release](https://camo.githubusercontent.com/31efab21b76c62be58d1baea3caa1c39403cf4c1c25547890c2c59dde27e4ad2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f546f6f626f2f486f702e7376673f7374796c653d666c61742d737175617265)](https://github.com/Toobo/Hop/releases/latest)[![PHP version requirement](https://camo.githubusercontent.com/e2aa4f4d8b99f5c03406910ddccd05e55adc414b755ed5e9682cf524262abfdd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f6f626f2f686f702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/toobo/hop)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

---

> Higher order predicates library.

---

What?
=====

[](#what)

A "higher order function" is a function that either returns a function or takes a function as argument.

A "functional predicate" is a function that receives one or more arguments (subject) and returns `true` or `false`.

**This library is a collections of functions that return functional predicates**.

Why?
====

[](#why)

In PHP there are some functions like `array_map`, `array_filter`, and so on, that take a functional predicate as argument.

For example:

```
$data = [
  'foo',
  1,
  true,
  'bar',
  [],
  ''
];

$strings = array_filter($data, 'is_string'); // ['foo', 'bar', '']
```

This can be done thanks to the fact that a `is_string` is a named function.

But if we need something more complex, e.g. we also want to strip empty strings, we need to:

```
$strings = array_filter($data, function($item) {
    return is_string($item) && $item !== '';
});
```

One of the functions of this library is `isType()` that accepts a string representing a type and returns a predicate that can be used to check subjects against that type.

Another of the functions of this library is `isNotEmpty()` that returns a predicate that verifies non-empty values.

Another function is `chain()` that takes an arbitrary number of predicates and returns a predicate that returns `true` when *all* the given predicates return true.

Using these 3 functions the code above can be written like this:

```
$strings = array_filter($data, Hop\chain(Hop\isType('string'), Hop\isNotEmpty()));
```

All the functions in this library are in `Hop` namespace.

Installation
============

[](#installation)

Served by Composer using `toobo/hop`.

List of functions
=================

[](#list-of-functions)

Here a list of all the functions currently provided by library (namespace omitted):

### General

[](#general)

- `always()` Return a predicate that always return `true`
- `never()` Return a predicate that always return `false`
- `isEmpty()`
- `isNotEmpty()`
- `isTrueish()`
- `isFalsey()`
- `isBooleanLooking()`

### Comparison

[](#comparison)

- `is($value)`
- `isNot($value)`
- `equals($value)`
- `notEquals($value)`
- `matches(string $regex)`
- `notMatches(string $regex)`
- `moreThan(int|float $limit)`
- `moreThanOrEqual(int|float $limit)`
- `lessThan(int|float $limit)`
- `lessThanOrEqual(int|float $limit)`
- `between(int|float $min, int|float $max)`
- `betweenInner(int|float $min, int|float $max)`
- `betweenLeft(int|float $min, int|float $max)`
- `betweenRight(int|float $min, int|float $max)`

### Type check

[](#type-check)

- `isType(string $type)` Works with scalar types, classes and interfaces
- `objectIs(string $classOrInterface)` Works with objects

### Var filtering check

[](#var-filtering-check)

- `filterVar(int $filter, $options = null)` Returns a predicate that applies `filter_var()` to subject using given filter and options.
- `isEmail()`
- `isUrl()`
- `isIp()`
- `isMac()`

### Size check

[](#size-check)

- `size(int $size)` Verify elements count of arrays and countable objects and string length
- `smallerThan(int $size)`
- `smallerThanOrEqual(int $size)`
- `biggerThan(int $size)`
- `biggerThanOrEqual(int $size)`
- `sizeBetween(int $min, int $max)`
- `sizeBetweenInner(int $min, int $max)`
- `sizeBetweenLeft(int $min, int $max)`
- `sizeBetweenRight(int $min, int $max)`

### Elements check (for arrays and strings)

[](#elements-check-for-arrays-and-strings)

- `contains(string $subString)` Verify a string contains a sub-string
- `startsWith(string $subString)` Verify a string starts with a sub-string
- `endsWith(string $subString)` Verify a string ends with a sub-string
- `has($item)` Verify an string contains an item
- `headIs(...$items)` Verify first item(s) of an array
- `tailIs(...$items)` Verify last item(s) of an array
- `in(...$items)` Verify an item is one of given items
- `notIn(...$items)` Verify an item is none of given items
- `intersect(...$items)` Verify an array has an non-empty intersection with given items
- `notIntersect(...$items)` Verify an array has an empty intersection with given items

### Array keys

[](#array-keys)

- `hasKey(string $key)`
- `hasNotKey(string $key)`
- `hasAllKeys(string ...$keys)`
- `hasAnyOfKeys(string ...$keys)`
- `hasNoneOfKeys(string ...$keys)`
- `hasNotAllKeys(string ...$keys)`
- `valueForKeyIs(string $key, $value)`
- `valueForKeyIsNot(string $key, $value)`
- `applyOnValueForKey(string $key, callable $callback)`

### Object methods

[](#object-methods)

- `hasMethod(string $method)`
- `classHasMethod(string $method)`
- `methodReturns(string $method, $value, ...$params)`

### Predicates composition

[](#predicates-composition)

- `not(callable $predicate)` Negate given predicate
- `chain(callable ...$predicates)` Combine predicates in AND mode
- `pool(callable ...$predicates)` Combine predicates in OR mode

### Misc

[](#misc)

- `applyAfter(callable $transformation, callable $predicate)` Returns a predicate which returns the result of the predicate, after it has been applied the input value, transformed by the `$transformation` function.
- `applyAfterMethod(string $method, callable $predicate)`

License
-------

[](#license)

Hop is open source and released under MIT license. See [LICENSE](./LICENSE) file for more info.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Total

4

Last Release

1309d ago

Major Versions

1.0.0 → 2.0.02022-10-14

PHP version history (3 changes)1.0.0PHP &gt;=7.2

2.0.0PHP &gt;=8.0

1.0.1PHP &gt;=7.2 &lt; 8

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2208282?v=4)[Giuseppe Mazzapica](/maintainers/gmazzap)[@gmazzap](https://github.com/gmazzap)

---

Top Contributors

[![gmazzap](https://avatars.githubusercontent.com/u/2208282?v=4)](https://github.com/gmazzap "gmazzap (12 commits)")

---

Tags

assertion-libraryfilteringfunctional-programminghigher-order-functionspredicate-logicpredicatesvalidationassertionsfunctionfilteringfunctional-programmingpredicates

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/toobo-hop/health.svg)

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

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M672](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)

PHPackages © 2026

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