{"id":19386971,"url":"https://github.com/bermudaphp/reflection-type-matcher","last_synced_at":"2025-04-23T23:30:48.749Z","repository":{"id":142263233,"uuid":"612373947","full_name":"bermudaphp/reflection-type-matcher","owner":"bermudaphp","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-05T13:50:41.000Z","size":15,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-09T21:18:27.297Z","etag":null,"topics":["reflection","reflection-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bermudaphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-10T19:59:03.000Z","updated_at":"2024-08-03T11:50:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"0f170452-8a48-460e-a08e-8be1e1e6ce8f","html_url":"https://github.com/bermudaphp/reflection-type-matcher","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermudaphp%2Freflection-type-matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermudaphp%2Freflection-type-matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermudaphp%2Freflection-type-matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermudaphp%2Freflection-type-matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bermudaphp","download_url":"https://codeload.github.com/bermudaphp/reflection-type-matcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223936990,"owners_count":17228140,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["reflection","reflection-api"],"created_at":"2024-11-10T10:08:00.531Z","updated_at":"2025-04-23T23:30:48.741Z","avatar_url":"https://github.com/bermudaphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeMatcher\n\n**TypeMatcher** is a robust PHP class for dynamic type validation using the Reflection API. It helps you determine whether a given variable conforms to a specified reflected type, supporting named types, union types, and intersection types. The class is designed for PHP 8 and later, taking advantage of modern language features like match expressions and strict type comparisons.\n\n## Features\n\n- **Named Type Matching**: Checks if a variable is an instance of a specified class or a built-in type.\n- **Union Type Matching**: Validates the variable against multiple possible types, ensuring it matches at least one.\n- **Intersection Type Matching**: Ensures the variable conforms to every type in a given intersection.\n- **Strict Comparison Option**: Use strict checks for numeric and string types or allow flexible comparisons when needed.\n- **Lightweight \u0026 Standalone**: Easily integrate this class into your projects without the overhead of a larger framework.\n\n# Install\n```bash\ncomposer require bermudaphp/reflection-type-matcher\n```\n\n# Usage\n```php\n    $reflector = new ReflectionFunction(static fn(int $a, int $b) =\u003e $a + $b);\n    $param = $reflector-\u003egetParameters()[0];\n        \n    TypeMatcher::match($param-\u003egetType(), '22'); // true\n    TypeMatcher::match($param-\u003egetType(), 22); // true\n    TypeMatcher::match($param-\u003egetType(), '22', true); // false\n    \n    $reflector = new ReflectionFunction(static fn(A\u0026B $arg) =\u003e $arg);\n    $param = $reflector-\u003egetParameters()[0];\n    \n    TypeMatcher::match($param-\u003egetType(), new class implements A, B {}) // true\n    TypeMatcher::match($param-\u003egetType(), new StdClass) // false\n   \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbermudaphp%2Freflection-type-matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbermudaphp%2Freflection-type-matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbermudaphp%2Freflection-type-matcher/lists"}