Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 637 Bytes

README.md

File metadata and controls

22 lines (16 loc) · 637 Bytes

Install

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