innmind/type

1.2.0 2024-02-17 08:56 UTC

This package is auto-updated.

Last update: 2024-10-17 10:23:07 UTC


README

Build Status codecov Type Coverage

This package allows to describe types as objects to check if a given type can accept a value or if it is compatible with another type.

Installation

composer require innmind/type

Usage

use Innmind\Type\{
    Build,
    Primitive,
};

final class Example
{
    private int $id;
}

$type = Build::fromReflection((new \ReflectionProperty(Example::class, 'id'))->getType());
$type->allows(42); // true
$type->allows('some-uuid'); // false

$type->accepts(Primitive::int()); // true
$type->accepts(Primitive::string()); // false