ixnode/php-checker

PHP Checker - A collection of various PHP types check classes.

0.1.9 2023-06-25 09:31 UTC

This package is auto-updated.

Last update: 2024-10-25 12:23:36 UTC


README

Release PHP PHPStan PHPCS LICENSE

A collection of various PHP types check classes.

Introduction

This package is helpful to validate complex data types like complex arrays and to comply with DocBlock declarations (static code analysis tools like PHPStan or Psalm). Uses and throws exceptions from ixnode/php-exception as a "one-liner". Instead of using the following code:

if (!is_array($value)) {
    throw new TypeInvalidException('array', gettype($this->value));
}

just use this one:

$checkedArray = (new Checker($value))->checkArray();

Installation

composer require ixnode/php-checker
vendor/bin/php-checker -V
php-checker 0.1.0 (12-30-2022 18:08:35) - Björn Hempel <bjoern@hempel.li>

Usage

Example 1

use Ixnode\PhpChecker\Checker;
$array = (new Checker(.0))->checkFloat();

Example 2

use Ixnode\PhpChecker\CheckerArray;
$array = (new CheckerArray([new Checker(123), new Checker(456), new Checker(678)])->checkClass(Checker::class);

Example 3

use Ixnode\PhpChecker\CheckerClass;
$array = (new CheckerClass(new Checker(123)))->check(Checker::class);

Example 4

use Ixnode\PhpChecker\CheckerJson;
$array = (new CheckerJson('{"1": 1, "2": 2, "3": 3}'))->check();

Available checkers

Class Ixnode\PhpChecker\Checker

Checks general data type specific properties.

Class Ixnode\PhpChecker\CheckerArray

Checks array specific properties.

Class Ixnode\PhpChecker\CheckerClass

Checks class specific properties.

Class Ixnode\PhpChecker\CheckerJson

Checks JSON specific properties.

Development

git clone git@github.com:ixnode/php-checker.git && cd php-checker
composer install
composer test

License

This tool is licensed under the MIT License - see the LICENSE file for details