PHPackages                             simple-as-fuck/php-validator - 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. simple-as-fuck/php-validator

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

simple-as-fuck/php-validator
============================

0.7.14(2mo ago)0165.0k↓30.4%25UnlicensePHPPHP ^8.2CI passing

Since Nov 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/simple-as-fuck/php-validator)[ Packagist](https://packagist.org/packages/simple-as-fuck/php-validator)[ RSS](/packages/simple-as-fuck-php-validator/feed)WikiDiscussions 0.7 Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (91)Used By (5)

Simple as fuck / Php Validator
==============================

[](#simple-as-fuck--php-validator)

Validator for php variables with intuitive rule chain, put inside mixed and you in the end get requested type.

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

[](#installation)

```
composer require simple-as-fuck/php-validator
```

Support
-------

[](#support)

If any PHP platform requirements in [composer.json](../composer.json) ends with security support, consider package version as unsupported except last version.

[PHP supported versions](https://www.php.net/supported-versions.php).

Usage
-----

[](#usage)

```
/** @var mixed $value */
$value = $config->get('some_value_name');

$rules = \SimpleAsFuck\Validator\Factory\Validator::make($value, 'Config "some_value_name" value');
$validValue = $rules->string()->notEmpty()->notNull();
// string value is not dump into validation message similarly to:
// https://www.php.net/manual/en/class.sensitiveparameter.php
$validSensitiveValue = $rules->string(sensitiveValue: true)->notEmpty()->notNull();
/*
 * now you have in $validValue really not empty string and even phpstan know the type without any annoying annotation
 * if validation failed \UnexpectedValueException('Config "some_value_name" value must ...') is thrown from rule chain
 */
$stringValues = $rules->array()->ofString()->notNull();

/*
 * shorter notation, value name in validator factory is optional and here is unnecessary,
 * validation exception is thrown in same line as config key name
 * so you should this find in your stacktrace and know than something is wrong in your config file
 */
\SimpleAsFuck\Validator\Factory\Validator::make($config->get('some_value_name'))->string()->notEmpty()->notNull();
```

This validation can be applied into any php variable and is appropriately usable for json decoded data. All rules have declared types for next rule in chain so not look for any rules list, your IDE should hint you available rules and rule chain is designed for preventing redundant rules or rule combination which do not make sense.

Validation exception type changing
----------------------------------

[](#validation-exception-type-changing)

You can change exception type throw from rule chain while validation failed by inject yours exception factory.

If you want throw some HTTP exception for validation http request beware of this validator is not suitable for validation user inputs.

First: validator fail in first unsuccessful rule in nested structure and throw only one exception even if there can be more validation fails.

Second: validator throw highly generated messages which can be for user unreadable and translation support is not in plan, for us developers messages should be fine.

Third: realise than we write in PHP server side application so the app should return data in some API format and view data should some weird javascript, native or mobile client app. Yes I know than even pc games are rendered in cloud but client pc has also some computing power and if client logic and html is rendered on server is only wasting of its power.

```
final class ExceptionFactory extends \SimpleAsFuck\Validator\Factory\Exception
{
    /**
     * @param non-empty-string $message
     */
    public function create(string $message): \Exception
    {
        return new \RuntimeException($message);
    }
}

$exceptionFactory = new \ExceptionFactory();

$value = new \SimpleAsFuck\Validator\Model\Validated(1);

$rules = new \SimpleAsFuck\Validator\Rule\General\Rules($exceptionFactory, 'variable', $value);

$validValue = $rules->int()->notNull();
```

Customization
-------------

[](#customization)

### User defined rule

[](#user-defined-rule)

You can create your rule and put it in the end of rule chain and this allow you to run some yours validation.

If you are validating something what is widely standardized, consider contribute into rule chain, for more nicely writing it or share some rule with others.

```
/**
 * @implements \SimpleAsFuck\Validator\Rule\Custom\UserDefinedRule
 */
final class GandalfRule implements \SimpleAsFuck\Validator\Rule\Custom\UserDefinedRule
{
    /**
     * @param string $value
     */
    public function validate($value): ?string
    {
        throw new \SimpleAsFuck\Validator\Model\ValueMust('not pass');
    }
}

$rules = \SimpleAsFuck\Validator\Factory\Validator::make('');

$rules->string()->custom(new \GandalfRule())->notNull();
```

### User class rule

[](#user-class-rule)

Validator rule chain always return some specific type so generic object is not in option. You are able to convert object into some class with validated structure.

```
/**
 * @implements \SimpleAsFuck\Validator\Rule\Custom\UserClassRule
 */
final class YourClassRule implements \SimpleAsFuck\Validator\Rule\Custom\UserClassRule
{
    public function validate(\SimpleAsFuck\Validator\Rule\Object\ObjectRule $object): YourClass
    {
        return new YourCass(
            $object->property('propertyName')->string()->max(30)->notNull()
            // some next property ...
        );
    }
}

/** @var mixed $data */

$rules = \SimpleAsFuck\Validator\Factory\Validator::make($data);

$yourObject = $rules->object()->class(new YourClassRule())->notNull();
$yourObjects = $rules->array()->ofClass(new YourClassRule())->notNull();
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance87

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 99.5% 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 ~17 days

Recently: every ~4 days

Total

91

Last Release

62d ago

PHP version history (4 changes)0.1.0PHP ^7.4|^8.0

0.4.14PHP ^8.0

0.4.15PHP ^8.1

0.7.6PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/dcf2ca03f52f05685f62127eaeb513e84856c4cbbdc728fb0eb99d6e659a7a37?d=identicon)[Triplkrypl](/maintainers/Triplkrypl)

---

Top Contributors

[![Triplkrypl](https://avatars.githubusercontent.com/u/15320684?v=4)](https://github.com/Triplkrypl "Triplkrypl (191 commits)")[![AlexKratky](https://avatars.githubusercontent.com/u/33813757?v=4)](https://github.com/AlexKratky "AlexKratky (1 commits)")

---

Tags

phpphpstan-max-levelsimplevariable-validation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/simple-as-fuck-php-validator/health.svg)

```
[![Health](https://phpackages.com/badges/simple-as-fuck-php-validator/health.svg)](https://phpackages.com/packages/simple-as-fuck-php-validator)
```

###  Alternatives

[aporat/store-receipt-validator

PHP receipt validator for Apple App Store and Amazon Appstore

6503.9M9](/packages/aporat-store-receipt-validator)[illuminate/validation

The Illuminate Validation package.

18936.7M1.4k](/packages/illuminate-validation)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15644.9M188](/packages/laminas-laminas-validator)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)[hyperf/validation

hyperf validation

122.1M166](/packages/hyperf-validation)

PHPackages © 2026

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