PHPackages                             daverandom/callback-validator - 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. daverandom/callback-validator

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

daverandom/callback-validator
=============================

Tools for validating callback signatures

4310.5k3PHP

Since Apr 3Pushed 7y ago8 watchersCompare

[ Source](https://github.com/DaveRandom/CallbackValidator)[ Packagist](https://packagist.org/packages/daverandom/callback-validator)[ RSS](/packages/daverandom-callback-validator/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Callback Validator
==================

[](#callback-validator)

Validates callback signatures against a prototype.

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/2db3775a6022a07c1bd967178a28d8f65ce42cafc7b96e30eccf54f08e381fc1/68747470733a2f2f7472617669732d63692e6f72672f4461766552616e646f6d2f43616c6c6261636b56616c696461746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/DaveRandom/CallbackValidator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/85415ec89477cdd3c4ab2d520799fa90827e6798d485a410dcdb825984fc0f16/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4461766552616e646f6d2f43616c6c6261636b56616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DaveRandom/CallbackValidator/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/331f65f5d6dde27f2a8dd905fa5b0d9f6c8945e3bae76e5f4f897143433b0ba9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4461766552616e646f6d2f43616c6c6261636b56616c696461746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/DaveRandom/CallbackValidator/?branch=master)

Usage
-----

[](#usage)

```
// Create a prototype function (can be any callable)
$prototype = function (A $a, B $b, $c): ?string {};

// Validate that callables match the prototype
$tests = [
    $prototype, // true
    function (A $a, B $b, $c) {}, // false - return type does not match
    function ($a, $b, $c): ?string {}, // true - arguments are contravariant
    function (A $a, B $b): ?string {}, // true - extra args don't cause errors
    function (A $a, B $b, $c, $d): ?string {}, // false - Insufficient args cause an error
    function (C $a, B $b, $c): ?string {}, // true if C is a supertype of A, false otherwise
    function (SuperTypeOfA $a, B $b, $c): ?string {}, // true
    function (A $a, B $b, $c): string {}, // true - return types are covariant
];

// Create a type from a prototype
$type = CallbackType::createFromCallable($prototype);

run_tests($type, $tests);

// ...or create a type by hand for more granular control over variance rules
$type = new CallbackType(
    new ReturnType(BuiltInTypes::STRING, ReturnType::NULLABLE | ReturnType::COVARIANT),
    new ParameterType('a', A::class),
    new ParameterType('b', B::class),
    new ParameterType('c')
);

run_tests($type, $tests);

function run_tests(CallbackType $type, array $tests)
{
    foreach ($tests as $test) {
        if ($type->isSatisfiedBy($test)) {
            echo "pass\n";
        } else {
            // CallbackType implements __toString() for easy inspections
            echo CallbackType::createFromCallable($test) . " does not satisfy {$type}\n";
        }
    }
}
```

TODO
----

[](#todo)

- Lots more tests
- Explain (text explanation of why callback does not validate)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.2% 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.

### Community

Maintainers

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

---

Top Contributors

[![DaveRandom](https://avatars.githubusercontent.com/u/2396425?v=4)](https://github.com/DaveRandom "DaveRandom (35 commits)")[![PeeHaa](https://avatars.githubusercontent.com/u/1330296?v=4)](https://github.com/PeeHaa "PeeHaa (1 commits)")

### Embed Badge

![Health badge](/badges/daverandom-callback-validator/health.svg)

```
[![Health](https://phpackages.com/badges/daverandom-callback-validator/health.svg)](https://phpackages.com/packages/daverandom-callback-validator)
```

###  Alternatives

[marcosh/php-validation-dsl

A DSL for validating data in a functional fashion

483.9k](/packages/marcosh-php-validation-dsl)

PHPackages © 2026

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