{"id":19527355,"url":"https://github.com/daverandom/callbackvalidator","last_synced_at":"2025-04-26T10:31:47.355Z","repository":{"id":56963182,"uuid":"85776684","full_name":"DaveRandom/CallbackValidator","owner":"DaveRandom","description":"Tools for validating callback signatures in PHP","archived":false,"fork":false,"pushed_at":"2018-12-31T16:13:34.000Z","size":60,"stargazers_count":44,"open_issues_count":0,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-04T11:51:11.567Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/DaveRandom.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}},"created_at":"2017-03-22T02:36:15.000Z","updated_at":"2023-05-08T05:03:59.000Z","dependencies_parsed_at":"2022-08-21T05:40:21.581Z","dependency_job_id":null,"html_url":"https://github.com/DaveRandom/CallbackValidator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FCallbackValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FCallbackValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FCallbackValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaveRandom%2FCallbackValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DaveRandom","download_url":"https://codeload.github.com/DaveRandom/CallbackValidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250972973,"owners_count":21516454,"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":[],"created_at":"2024-11-11T01:14:43.074Z","updated_at":"2025-04-26T10:31:47.102Z","avatar_url":"https://github.com/DaveRandom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Callback Validator\n==================\n\nValidates callback signatures against a prototype.\n\n## Status\n\n[![Build Status](https://travis-ci.org/DaveRandom/CallbackValidator.svg?branch=master)](https://travis-ci.org/DaveRandom/CallbackValidator)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/DaveRandom/CallbackValidator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/DaveRandom/CallbackValidator/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/DaveRandom/CallbackValidator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/DaveRandom/CallbackValidator/?branch=master)\n\n## Usage\n\n```php\n// Create a prototype function (can be any callable)\n$prototype = function (A $a, B $b, $c): ?string {};\n\n// Validate that callables match the prototype\n$tests = [\n    $prototype, // true\n    function (A $a, B $b, $c) {}, // false - return type does not match\n    function ($a, $b, $c): ?string {}, // true - arguments are contravariant\n    function (A $a, B $b): ?string {}, // true - extra args don't cause errors\n    function (A $a, B $b, $c, $d): ?string {}, // false - Insufficient args cause an error\n    function (C $a, B $b, $c): ?string {}, // true if C is a supertype of A, false otherwise\n    function (SuperTypeOfA $a, B $b, $c): ?string {}, // true\n    function (A $a, B $b, $c): string {}, // true - return types are covariant\n];\n\n// Create a type from a prototype\n$type = CallbackType::createFromCallable($prototype);\n\nrun_tests($type, $tests);\n\n// ...or create a type by hand for more granular control over variance rules\n$type = new CallbackType(\n    new ReturnType(BuiltInTypes::STRING, ReturnType::NULLABLE | ReturnType::COVARIANT),\n    new ParameterType('a', A::class),\n    new ParameterType('b', B::class),\n    new ParameterType('c')\n);\n\nrun_tests($type, $tests);\n\nfunction run_tests(CallbackType $type, array $tests)\n{\n    foreach ($tests as $test) {\n        if ($type-\u003eisSatisfiedBy($test)) {\n            echo \"pass\\n\";\n        } else {\n            // CallbackType implements __toString() for easy inspections\n            echo CallbackType::createFromCallable($test) . \" does not satisfy {$type}\\n\";\n        }\n    }\n}\n```\n\n## TODO\n\n- Lots more tests\n- Explain (text explanation of why callback does not validate)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaverandom%2Fcallbackvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaverandom%2Fcallbackvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaverandom%2Fcallbackvalidator/lists"}