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.
composer require innmind/typeuse 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