PHPackages                             macfja/chain-select - 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. macfja/chain-select

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

macfja/chain-select
===================

06PHP

Since Apr 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/MacFJA/ChainSelect)[ Packagist](https://packagist.org/packages/macfja/chain-select)[ RSS](/packages/macfja-chain-select/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

ChainSelect
===========

[](#chainselect)

Find the best option

Installation
------------

[](#installation)

The best way to install this lib is to use Composer.

```
$ composer require macfja/chain-select

```

Usage
-----

[](#usage)

```
$runner = new Runner();
$runner->setMinAcceptableScore(0.75);
$runner->addHandler(new MyCustomHandler());
$runner->addHandler(new MyOtherHandler());
$runner->setContext($myContext);

$runner->getFirstAcceptable();
```

### Examples

[](#examples)

Simple example with a corpus of text

```
$existingKeywords = [/* your code here*/];
$runner = CorpusHandlerHelper::addCorpus(new Runner(), $existingKeywords);
$runner->setContext($userInput);
$result = $runner->getBestMatch();

if ($result->getScore() === 1.0) {
    // your code here. Example:
    //$page->addKeyword($result->getResult());
} else {
    // your code here. Example:
    //echo 'Did you mean "'.$result->getResult().'"?';
}
```

---

A more complex example

```
$runner = new Runner();
$runner->setMinAcceptableScore(0.75);
$runner->addHandler(new class implements HandlerInterface {
    public function execute($context)
    {
        // Some external request that return a score/confidence value
        $percent = doSomethingAwesome($context);
        return new HandlerResult($percent/100, $percent, $context, $this);
    }
    public function accept($context)
    {
        return true;
    }
});
$runner->addHandler(new class implements HandlerInterface {
    public function execute($context)
    {
        // Some voodoo calculation with the context
        $noteOnTen = myHardWorkCalculation($context);
        return new HandlerResult($percent/10, $noteOnTen, $context, $this);
    }
    public function accept($context)
    {
        return true;
    }
});
$runner->setContext($myContext);

$result = $runner->getFirstAcceptable();

var_dump($result);
```

Contributing
------------

[](#contributing)

You are welcome to create new issues if you found a bug or have an idea to improve this lib.

You can also create Pull Request.

### Code quality

[](#code-quality)

The code follow the PSR-1, PSR-2, PSR-4.

The code is validated/monitored with the following tools :

> Php LOC, Php CPD, PhpCS, Pdepend, PHPMD, PhpMetrics, Parallel-Lint, PhpAssumption, PhpMagicNumberDetector, PhpStan, Psalm, PhpUnit, Infection

You can run the full test-suite with the command:

```
$ composer tests

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1475671?v=4)[MacFJA](/maintainers/MacFJA)[@MacFJA](https://github.com/MacFJA)

---

Top Contributors

[![MacFJA](https://avatars.githubusercontent.com/u/1475671?v=4)](https://github.com/MacFJA "MacFJA (1 commits)")

### Embed Badge

![Health badge](/badges/macfja-chain-select/health.svg)

```
[![Health](https://phpackages.com/badges/macfja-chain-select/health.svg)](https://phpackages.com/packages/macfja-chain-select)
```

###  Alternatives

[rich-davis1/phpw2v

A PHP implementation of Word2Vec, a popular word embedding algorithm created by Tomas Mikolov and popularized by Radim Řehůřek &amp; Peter Sojka with the Gensim Python library.

471.2k](/packages/rich-davis1-phpw2v)[warete/moonshine-upgrade

Package for upgrade MoonShine

121.5k](/packages/warete-moonshine-upgrade)

PHPackages © 2026

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