PHPackages                             alexeyshockov/pattern-matcher - 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. alexeyshockov/pattern-matcher

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

alexeyshockov/pattern-matcher
=============================

Pattern matching for PHP.

v0.1.1(7y ago)13621MITPHPPHP ~5.6 || ~7.0

Since Feb 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/alexeyshockov/pattern-matcher)[ Packagist](https://packagist.org/packages/alexeyshockov/pattern-matcher)[ Docs](http://github.com/alexeyshockov/pattern-matcher)[ RSS](/packages/alexeyshockov-pattern-matcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

pattern-matcher
===============

[](#pattern-matcher)

Simple pattern matching technique from functional languages. For PHP.

Examples
--------

[](#examples)

With Option from [schmittjoh/php-option](https://github.com/schmittjoh/php-option):

```
use function PatternMatcher\option_matcher;

$matcher = option_matcher(function ($className, ReflectionClass $class) {
    return ($class->getName() == $className) || $class->isSubclassOf($className);
})
    ->addCase(InputInterface::class, $input)
    ->addCase(OutputInterface::class, $output)
    ->addCase(Output::class, new Output($output))
    ->addCase(HelperInterface::class, function (ReflectionClass $class) {
        foreach ($this->getHelperSet() as $helper) {
            if ($class->isInstance($helper)) {
                return $helper;
            }
        }

        throw new InvalidArgumentException("Helper with type " . $class->getName() . " is not registered.");
    })
;

$argument = $argumentDefinition->getClass()
    ->flatMap($matcher)
    ->getOrThrow(new InvalidArgumentException(
        'Parameter $' . $argumentDefinition->getName() . ': type is missed or not supported.'
    ));
```

Or with [ColadaX](https://github.com/alexeyshockov/colada-x):

```
use PatternMatcher\matcher;
use PatternMatcher\all;
use Colada\x;

matcher()
    ->addCase(all(x()->isActive(), x()->hasFriends()), )
```

Or pure:

```
$matcher = (new PatternMatcher(function ($className, ReflectionClass $class) {
    return ($class->getName() == $className) || $class->isSubclassOf($className);
}))
    ->addCase(InputInterface::class, $input)
    ->addCase(OutputInterface::class, $output)
    ->addCase(Output::class, new Output($output))
    ->addCase(HelperInterface::class, function (ReflectionClass $class) {
        foreach ($this->getHelperSet() as $helper) {
            if ($class->isInstance($helper)) {
                return $helper;
            }
        }

        throw new InvalidArgumentException("Helper with type " . $class->getName() . " is not registered.");
    })
;

$argument = $argumentDefinition->getClass()
    ->flatMap($matcher)
    ->getOrThrow(new InvalidArgumentException(
        'Parameter $' . $argumentDefinition->getName() . ': type is missed or not supported.'
    ));
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

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

Total

2

Last Release

2653d ago

### Community

Maintainers

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

---

Top Contributors

[![alexeyshockov](https://avatars.githubusercontent.com/u/203120?v=4)](https://github.com/alexeyshockov "alexeyshockov (6 commits)")

---

Tags

collectionsfunctional

### Embed Badge

![Health badge](/badges/alexeyshockov-pattern-matcher/health.svg)

```
[![Health](https://phpackages.com/badges/alexeyshockov-pattern-matcher/health.svg)](https://phpackages.com/packages/alexeyshockov-pattern-matcher)
```

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[lstrojny/functional-php

Functional primitives for PHP

2.0k7.3M48](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[dusank/knapsack

Collection library for PHP

5351.0M25](/packages/dusank-knapsack)[lambdish/phunctional

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)

PHPackages © 2026

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