bermudaphp/reflection-type-matcher

v1.0.1 2024-05-05 13:49 UTC

This package is auto-updated.

Last update: 2024-11-05 14:53:27 UTC


README

composer require bermudaphp/reflection-type-matcher

Usage

    $reflector = new ReflectionFunction(static fn(int $a, int $b) => $a + $b);
    $param = $reflector->getParameters()[0];
    
    $matcher = new TypeMatcher();
    
    $matcher->match($param->getType(), '22'); // false
    $matcher->match($param->getType(), 22); // true
    
    $reflector = new ReflectionFunction(static fn(A&B $arg) => $arg);
    $param = $reflector->getParameters()[0];
    
    $matcher->match($param->getType(), new class implements A, B {}) // true
    $matcher->match($param->getType(), new StdClass) // false