qlimix/validation

Validate data individually or by set

3.0.0 2021-02-22 20:26 UTC

This package is auto-updated.

Last update: 2024-11-23 04:30:10 UTC


README

Travis CI Coveralls Mutation testing badge Packagist MIT License

Validate data individually or by set.

Install

Using Composer:

$ composer require qlimix/validation

usage

Example 1 Collection

[
    {
        "foo": "bar",
        "foobar": {
            "bar": 1,
            "foo": "example"
        }
    },
    {
        "foo": "foo",
        "foobar": {
            "bar": 2,
            "foo": "example1"
        }
    }
]
<?php

use Qlimix\Validation\CollectionValidation;
use Qlimix\Validation\Inspector\HashInspector;
use Qlimix\Validation\Inspector\KeyInspector;
use Qlimix\Validation\Key;

$example1 = new CollectionValidation([
    new HashInspector([new Key('foo', true, [])]), // add validators
    new KeyInspector('foobar', true, [
        new HashInspector([
            new Key('bar', true, []), // add validators
            new Key('foo', true, []), // add validators
        ])
    ])
]);

Example 2 key values

{
    "foo": "foobar",
    "foobar": {
        "bar": 42,
        "foo": "example2"
    }
}
<?php

use Qlimix\Validation\Inspector\HashInspector;
use Qlimix\Validation\Inspector\KeyInspector;
use Qlimix\Validation\InspectorValidation;
use Qlimix\Validation\Key;

$example2 = new InspectorValidation([
    new HashInspector([new Key('foo', true, [])]), // add validators
    new KeyInspector('foobar', true, [
        new HashInspector([
            new Key('bar', true, []), // add validators
            new Key('bar', true, []), // add validators
        ])
    ])
]);

Testing

To run all unit tests locally with PHPUnit:

$ vendor/bin/phpunit

Quality

To ensure code quality run grumphp which will run all tools:

$ vendor/bin/grumphp run

Contributing

Please see CONTRIBUTING for details.