PHPackages                             stan-angeloff/guard - 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. stan-angeloff/guard

AbandonedArchivedLibrary

stan-angeloff/guard
===================

Safe-conducts for your PHP. Kills up to 99.9% of bad arguments.

35PHP

Since Jul 10Pushed 12y ago1 watchersCompare

[ Source](https://github.com/StanAngeloff/php-guard)[ Packagist](https://packagist.org/packages/stan-angeloff/guard)[ RSS](/packages/stan-angeloff-guard/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Guard
=====

[](#guard)

[![Build Status](https://camo.githubusercontent.com/1f6d132bd7ac2ece8838c62c0b40ee3ec90d449b88b99f83e3f854eeccb489c7/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f5374616e416e67656c6f66662f7068702d67756172642e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/StanAngeloff/php-guard) [![Coverage Status](https://camo.githubusercontent.com/e40d6035b04f74585164212f1be24d9f55e373983844741de8da3e6c5c8f9367/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f5374616e416e67656c6f66662f7068702d67756172642f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/StanAngeloff/php-guard?branch=master)

Safe-conducts for your PHP. Kills up to 99.9% of bad arguments.

**WIP**.

```
function add($a, $b)
{
    \Guard\Conditions::requires($a, 'a')->isNumeric();
    \Guard\Conditions::requires($b, 'b')->isNumeric();
    return $a + $b;
}

add(1, 2);

add('string', 2);
# => \Guard\Exception\ConditionEvaluationException(
#     'The condition "isNumeric" for argument "a" failed to evaluate.',
#     \Guard\Exception\InvalidArgumentException(
#         'The value "\'string\'" is not numeric.'
#     )
# )
```

Installing using Composer
-------------------------

[](#installing-using-composer)

```
# Run this in your terminal to get the latest Composer version:
$ curl -sS https://getcomposer.org/installer | php

# ...or if you don't have cURL:
$ php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

# Add Guard as a dependency:
$ php composer.phar require 'stan-angeloff/guard'
```

Usage
=====

[](#usage)

After installing, you need to require Composer's autoloader file:

```
require 'vendor/autoload.php';
```

To enforce conditions on your arguments, use:

```
\Guard\Conditions::requires($value, $argumentName)
    ->condition1()
    ->condition2('option, e.g., interface name');
```

where `$value` is the argument value and `$argumentName` is the argument name (see example above). Conditions can be chained.

Conditions
==========

[](#conditions)

- `instanceOf($className)`

    Throws an exception if the value is not an object or an instance of the expected `$className`.
- `isNotNull()`

    Throws an exception if the value is `NULL` (empty values are allowed, e.g., an empty string `''`).
- `isNumeric()`

    Throws an exception if the value is not numeric.
- `typeOf($internalType)`

    Throws an exception if the type of the value is not the expected one.

    See [gettype](http://php.net/gettype) for a full list of possible types.

---

**[LICENSE.AGPL-3.0](https://raw.github.com/StanAngeloff/php-guard/master/LICENSE.AGPL-3.0)**

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community5

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

---

Top Contributors

[![StanAngeloff](https://avatars.githubusercontent.com/u/93127?v=4)](https://github.com/StanAngeloff "StanAngeloff (24 commits)")

### Embed Badge

![Health badge](/badges/stan-angeloff-guard/health.svg)

```
[![Health](https://phpackages.com/badges/stan-angeloff-guard/health.svg)](https://phpackages.com/packages/stan-angeloff-guard)
```

PHPackages © 2026

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