PHPackages                             localheinz/specification - 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. localheinz/specification

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

localheinz/specification
========================

Provides specifications following the paper by Eric Evans and Martin Fowler.

0.1.0(8y ago)414MITPHPPHP ^7.0

Since Jun 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/localheinz/specification)[ Packagist](https://packagist.org/packages/localheinz/specification)[ RSS](/packages/localheinz-specification/feed)WikiDiscussions master Synced 3d ago

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

specification
=============

[](#specification)

[![CI Status](https://github.com/localheinz/php-library-template/workflows/Continuous%20Integration/badge.svg)](https://github.com/localheinz/php-library-template/actions)[![codecov](https://camo.githubusercontent.com/1a73c3ffe7b69d4a903dcffa473251efd2a54e80ec4e3ac52509c3016d937794/68747470733a2f2f636f6465636f762e696f2f67682f6c6f63616c6865696e7a2f73706563696669636174696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/localheinz/specification)[![Latest Stable Version](https://camo.githubusercontent.com/295d297b43f1f779fd47fee29dc08445e36d7fb1b09b2a058f58e7ee041d503b/68747470733a2f2f706f7365722e707567782e6f72672f6c6f63616c6865696e7a2f73706563696669636174696f6e2f762f737461626c65)](https://packagist.org/packages/localheinz/specification)[![Total Downloads](https://camo.githubusercontent.com/d4dc0c3633b70d920c04537694fd97491d66bc97dfb9b83ea028b8987dc243ea/68747470733a2f2f706f7365722e707567782e6f72672f6c6f63616c6865696e7a2f73706563696669636174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/localheinz/specification)

Provides specifications following the paper by [Eric Evans and Martin Fowler](http://martinfowler.com/apsupp/spec.pdf), also see [Wikipedia: Specification Pattern](https://en.wikipedia.org/wiki/Specification_pattern).

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

[](#installation)

Run

```
$ composer require localheinz/specification

```

Usage
-----

[](#usage)

### `SpecificationInterface`

[](#specificationinterface)

Implement `Localheinz\Specification\SpecificationInterface` in your specifications:

```
namespace Foo\Bar;

use Localheinz\Specification\SpecificationInterface;

final class IsInstanceOfStdClass implements SpecificationInterface
{
    public function isSatisfiedBy($candidate): bool
    {
        return $candidate instanceof \stdClass;
    }
}

final class HasFooProperty implements SpecificationInterface
{
    public function isSatisfiedBy($candidate): bool
    {
        return property_exists($candidate, 'foo');
    }
}

final class HasBarProperty implements SpecificationInterface
{
    public function isSatisfiedBy($candidate): bool
    {
        return property_exists($candidate, 'bar');
    }
}
```

### `AndSpecification`

[](#andspecification)

Use `Localheinz\Specification\AndSpecification` to compose a specification from specifications which all need to be satisfied:

```
use Localheinz\Specification\AndSpecification;
use Localheinz\Specification\Test\Fixture;

$specification = new AndSpecification(
    new Fixture\Specification\IsInstanceOfStdClass(),
    new Fixture\Specification\HasFooProperty(),
    new Fixture\Specification\HasBarProperty()
);

$candidate = new \stdClass();

$candidate->foo = 9000;
$candidate->bar = 'Hello, my name is Jane';

$specification->isSatisfiedBy($candidate); // true
```

### `OrSpecification`

[](#orspecification)

Use `Localheinz\Specification\OrSpecification` to compose a specification from specifications where only one needs to be satisfied:

```
use Localheinz\Specification\OrSpecification;
use Localheinz\Specification\Test\Fixture;

$specification = new OrSpecification(
    new Fixture\Specification\IsInstanceOfStdClass(),
    new Fixture\Specification\HasFooProperty(),
    new Fixture\Specification\HasBarProperty()
);

$candidate = new \stdClass();

$specification->isSatisfiedBy($candidate); // true
```

### `NotSpecification`

[](#notspecification)

Use `Localheinz\Specification\NotSpecification` to compose a specification from specifications where none should be satisfied:

```
use Localheinz\Specification\NotSpecification;
use Localheinz\Specification\Test\Fixture;

$specification = new NotSpecification(
    new Fixture\Specification\IsInstanceOfStdClass(),
    new Fixture\Specification\HasFooProperty(),
    new Fixture\Specification\HasBarProperty()
);

$candidate = new \SplObjectStorage();

$specification->isSatisfiedBy($candidate); // true
```

### Mix and match

[](#mix-and-match)

Mix and match all of the specifications to your need:

```
use Localheinz\Specification\AndSpecification;
use Localheinz\Specification\NotSpecification;
use Localheinz\Specification\OrSpecification;
use Localheinz\Specification\Test\Fixture;

$specification = new AndSpecification(
    new NotSpecification(new Fixture\Specification\IsInstanceOfStdClass()),
    new OrSpecification(
        new Fixture\Specification\HasFooProperty(),
        new Fixture\Specification\HasBarProperty()
    )
);

class Baz
{
    public $foo;
}

$candidate = new Baz();

$specification->isSatisfiedBy($candidate); // true
```

Changelog
---------

[](#changelog)

Please have a look at [`CHANGELOG.md`](CHANGELOG.md).

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

[](#contributing)

Please have a look at [`CONTRIBUTING.md`](.github/CONTRIBUTING.md).

Code of Conduct
---------------

[](#code-of-conduct)

Please have a look at [`CODE_OF_CONDUCT.md`](.github/CODE_OF_CONDUCT.md).

License
-------

[](#license)

This package is licensed using the MIT License.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3262d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8cabc9efd157e2b47aa5aa9830180f5ebd07813cc3e93ff1a9993b2c3d264909?d=identicon)[localheinz](/maintainers/localheinz)

---

Top Contributors

[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (149 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (5 commits)")

---

Tags

specification

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/localheinz-specification/health.svg)

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

PHPackages © 2026

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