PHPackages                             plaf/contract - 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. plaf/contract

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

plaf/contract
=============

Simple contracts library for PHP

16PHP

Since Aug 12Pushed 12y ago1 watchersCompare

[ Source](https://github.com/plaf/contract)[ Packagist](https://packagist.org/packages/plaf/contract)[ RSS](/packages/plaf-contract/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Plaf\\Contract
==============

[](#plafcontract)

Simple contracts for PHP
========================

[](#simple-contracts-for-php)

A part of Plaf - PHP library: Additional functionality

Functionality for ensuring contract compliance in terms of value type / range constraints. It should not be treated as validation, but specification of usage boundaries for programmers. Correctly covered code will behave predictable: it will work as designed by it's author or not work at all.

Usage example:
--------------

[](#usage-example)

```
use Plaf\Contract\Contract;

class EntitySaver {

    public function saveEntity($entity) {
        Contract::ensureNotNull($entity);
    }

}

use Plaf\Contract\Contract;

class Order {

    const STATE_NEW;
    const STATE_PREPARING;
    const STATE_SHIPPED;
    const STATE_COMPLETED;

    private $state;

    public function setState($state) {
        Contract::ensureInArray($state, array(
            self::STATE_NEW,
            self::STATE_PREPARING,
            self::STATE_SHIPPED,
            self::STATE_COMPLETED
        ));
    }

}

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

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/172711?v=4)[Valeriy](/maintainers/tverdohleb)[@tverdohleb](https://github.com/tverdohleb)

---

Top Contributors

[![tverdohleb](https://avatars.githubusercontent.com/u/172711?v=4)](https://github.com/tverdohleb "tverdohleb (2 commits)")

### Embed Badge

![Health badge](/badges/plaf-contract/health.svg)

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

###  Alternatives

[mehrpadin/superfish

Superfish library for the Drupal Superfish module.

951.3M](/packages/mehrpadin-superfish)[svanderburg/composer2nix

Generate Nix expressions to build PHP composer packages

925.9k](/packages/svanderburg-composer2nix)

PHPackages © 2026

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