PHPackages                             carlosv2/can - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. carlosv2/can

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

carlosv2/can
============

Tool for easy and powerful data validations

1.4.1(8y ago)11.3k1MITPHP ~5.4 || ~7.0

Since May 28Compare

[ Source](https://github.com/carlosV2/Can)[ Packagist](https://packagist.org/packages/carlosv2/can)[ RSS](/packages/carlosv2-can/feed)WikiDiscussions Synced today

READMEChangelog (6)Dependencies (1)Versions (7)Used By (1)

Can
===

[](#can)

Tool for easy and powerful data validations.

[![License](https://camo.githubusercontent.com/1d2c7fc8f503498211ed5d910d9ee9e2d2b326b454aedc81e9600e0ee7579c21/68747470733a2f2f706f7365722e707567782e6f72672f6361726c6f7376322f63616e2f6c6963656e7365)](https://packagist.org/packages/carlosv2/can)[![Build Status](https://camo.githubusercontent.com/55415c3dfbca60709826e977b40d1ad69b3087c024c804e17e7cecec66d392ce/68747470733a2f2f7472617669732d63692e6f72672f6361726c6f7356322f43616e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/carlosV2/Can)[![SensioLabsInsight](https://camo.githubusercontent.com/72e9f124ebbb71f75a8742d2d344c2db5280fbb6b58e5f747697f9c530f1c817/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f62633536336634352d353235642d343836322d616461662d3134396263303635373862332f6d696e692e706e67)](https://insight.sensiolabs.com/projects/bc563f45-525d-4862-adaf-149bc06578b3)

Why
---

[](#why)

Imagine I give you this data:

```
$data = [
	'key1' => 123,
	'key2' => 'abc',
	'key3' => true
];

```

And then I ask you to validate it according to the following constraints:

- It must be an array.
- `key1` must contain an integer between `100` and `200`.
- `key2` must contain a non-empty string.
- `key3` must contain either a boolean or a callable.
- If `key4` is set, it must be an array with a maximum of `3` items.
- It cannot have any other key.

How long would your code to validate `$data` be?

Using this project, it can be validated with this code:

```
can($data)->claim(To::beArray()
    ->withKey('key1')->expected(To::beInteger()->withMin(100)->withMax(200))
    ->withKey('key2')->expected(To::beString()->withMinLength(1))
    ->withKey('key3')->expected(To::beOneOf(To::beBoolean(), To::beCallable()))
    ->withKey('key4')->expected(To::beOptionalAnd(To::beArray()->withMaxCount(3)))
    ->withNoOtherKeys()
);

```

Install
-------

[](#install)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this project:

```
$ composer require carlosv2/can
```

This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Documentation
-------------

[](#documentation)

Available documentation:

- [Extending the library with your own asserters](https://github.com/carlosV2/Can/blob/master/docs/extending.md)
- Bundled extensions
    - Primitive types extension
        - [String](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/string.md)
        - [Integer](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/integer.md)
        - [Float](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/float.md)
        - [Array](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/array.md)
        - [Null](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/null.md)
        - [Boolean](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/boolean.md)
        - [Callable](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/callable.md)
        - [Object](https://github.com/carlosV2/Can/blob/master/docs/PrimitiveTypesExtension/object.md)
    - Constrints extension
        - [One of](https://github.com/carlosV2/Can/blob/master/docs/ConstraintsExtension/one_of.md)
        - [All of](https://github.com/carlosV2/Can/blob/master/docs/ConstraintsExtension/all_of.md)
        - [Optional and](https://github.com/carlosV2/Can/blob/master/docs/ConstraintsExtension/optional_and.md)
        - [Equals to](https://github.com/carlosV2/Can/blob/master/docs/ConstraintsExtension/equals_to.md)
        - [Like](https://github.com/carlosV2/Can/blob/master/docs/ConstraintsExtension/like.md)
        - [Set](https://github.com/carlosV2/Can/blob/master/docs/ConstraintsExtension/set.md)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~84 days

Recently: every ~10 days

Total

6

Last Release

3262d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.4,&lt;7.1

1.4.1PHP ~5.4 || ~7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2642839?v=4)[Carlos Ortega](/maintainers/carlosV2)[@carlosV2](https://github.com/carlosV2)

---

Top Contributors

[![carlosV2](https://avatars.githubusercontent.com/u/2642839?v=4)](https://github.com/carlosV2 "carlosV2 (10 commits)")[![DavidGarciaCat](https://avatars.githubusercontent.com/u/7809429?v=4)](https://github.com/DavidGarciaCat "DavidGarciaCat (1 commits)")

---

Tags

datavalidateextensiblecan

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k917.5M1.5k](/packages/webmozart-assert)[wixel/gump

A fast, extensible &amp; stand-alone PHP input validation class that allows you to validate any data.

1.2k1.4M31](/packages/wixel-gump)[inhere/php-validate

generic data validate, filter library of the php

26089.0k13](/packages/inhere-php-validate)[sadegh19b/laravel-persian-validation

A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers

18596.0k1](/packages/sadegh19b-laravel-persian-validation)[abcaeffchen/sepa-utilities

SepaUtilities provides useful methods for validating and sanitizing inputs used in SEPA files supporting PHP &gt;= 8.1.

312.0M2](/packages/abcaeffchen-sepa-utilities)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65393.6k9](/packages/awurth-slim-validation)

PHPackages © 2026

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