PHPackages                             guardsman/guardsman - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. guardsman/guardsman

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

guardsman/guardsman
===================

Guard clause assertion library to enforce parameter preconditions

v1.2.0(9y ago)32.4k1MITPHPPHP &gt;=5.5

Since Jan 31Pushed 9y ago2 watchersCompare

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

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

Guardsman 💂‍♂️
==============

[](#guardsman-guardsman)

[![travis](https://camo.githubusercontent.com/c9c6d314c4e1d4d8dd498fe95fc8c98dd68004e866eb879d277f43ef09fe2485/68747470733a2f2f7472617669732d63692e6f72672f6775617264736d616e2f6775617264736d616e2e737667)](https://camo.githubusercontent.com/c9c6d314c4e1d4d8dd498fe95fc8c98dd68004e866eb879d277f43ef09fe2485/68747470733a2f2f7472617669732d63692e6f72672f6775617264736d616e2f6775617264736d616e2e737667)

A guard clause assertion library to enforce parameter preconditions.

This provides a framework free, simple, chainable api for method parameter validation that throws exceptions on failure.

It is not intended as a validation library for end user input. If this is your use case then you should try one of these [validation libraries](https://packagist.org/search/?q=validation) instead.

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

[](#installation)

```
composer require guardsman/guardsman
```

Example Usage
-------------

[](#example-usage)

```
public function rename($name) {
    \Guardsman\check($name)
        ->isString()
        ->isNotEmpty();

    …
}
```

```
public function setSeconds($seconds) {
    \Guardsman\check($seconds)
        ->isInteger()
        ->isGreaterThanOrEqualTo(0)
        ->isLessThan(60);

    …
}
```

```
public function changeStatus($status) {
    \Guardsman\check($status)
        ->isValueOf(self::validStatuses);

    …
}
```

Preconditions
-------------

[](#preconditions)

### Array

[](#array)

```
\Guardsman\check($subject)->isValueOf(array $array);
\Guardsman\check($subject)->isNotValueOf(array $array);
\Guardsman\check($subject)->isKeyOf(array $array);
\Guardsman\check($subject)->isNotKeyOf(array $array);
```

### DateTime

[](#datetime)

*Methods will first check that the subject is an instance of `\DateTimeInterface`*

```
\Guardsman\check($subject)->isBefore(\DateTimeInterface $limit);
\Guardsman\check($subject)->isBeforeOrEqualTo(\DateTimeInterface $limit);
\Guardsman\check($subject)->isAfter(\DateTimeInterface $limit);
\Guardsman\check($subject)->isAfterOrEqualTo(\DateTimeInterface $limit);
```

### Empty

[](#empty)

```
\Guardsman\check($subject)->isNotEmpty();
```

### Number

[](#number)

*Methods that accept a limit will first check that the subject is numeric.**Limits will then be checked to ensure they are numeric and positive.*

```
\Guardsman\check($subject)->isNumeric();
\Guardsman\check($subject)->isInteger();
\Guardsman\check($subject)->isFloat();
\Guardsman\check($subject)->isGreaterThan($limit);
\Guardsman\check($subject)->isGreaterThanOrEqualTo($limit);
\Guardsman\check($subject)->isLessThan($limit);
\Guardsman\check($subject)->isLessThanOrEqualTo($limit);
\Guardsman\check($subject)->isPositive();
\Guardsman\check($subject)->isNegative();
```

### String

[](#string)

*Methods that accept a limit will first check that the subject is a string and that the encoding matches mb\_internal\_encoding**Limits will then be checked to ensure they are numeric and positive.*

```
\Guardsman\check($subject)->isString();
\Guardsman\check($subject)->isShorterThan($limit);
\Guardsman\check($subject)->isShorterThanOrEqualTo($limit);
\Guardsman\check($subject)->isLongerThan($limit);
\Guardsman\check($subject)->isLongerThanOrEqualTo($limit);
\Guardsman\check($subject)->matchesRegex($pattern);
```

Extending Guardsman
-------------------

[](#extending-guardsman)

Simply extend the Guardsman class with your own methods and create a check function under your namespace.

src\\Your\\Namespace\\SuperGuard.php

```
namespace Your\Namespace;

class SuperGuard extends \Guardsman\Guardsman
{
    public function isYourPreconditionMethod()
    {
        …
    }
}
```

src\\Your\\Namespace\\check.php

```
namespace Your\Namespace;

function check($subject)
{
    return new SuperGuard($subject);
}
```

composer.json

```
    "autoload": {
        "files": ["src/Your/Namespace/check.php"]
    }

```

Usage:

```
\Your\Namespace\check($subject)->isYourPreconditionMethod();
```

### Show Thanks

[](#show-thanks)

If you find this useful then please show your thanks with [a small donation](https://paypal.me/le6o/10).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3595d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00027acf5ae7a8c0cb9987722080ed8d03c8da2e93802bd8cd6c4158b19db0e4?d=identicon)[le6o](/maintainers/le6o)

---

Top Contributors

[![le6o](https://avatars.githubusercontent.com/u/103849?v=4)](https://github.com/le6o "le6o (117 commits)")

---

Tags

assertion-libraryguardphppreconditionsvalidationassertassertionvalidateparameterconstraintargumentguardpreconditionascertain

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[elliotchance/concise

Concise is test framework for using plain English and minimal code, built on PHPUnit.

45223.8k4](/packages/elliotchance-concise)[nilportugues/assert

A simple and elegant assertion and guard methods library for input validation.

1066.0k7](/packages/nilportugues-assert)[respect/assertion

The power of Respect\\Validation into an assertion library

2828.0k](/packages/respect-assertion)

PHPackages © 2026

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