{"id":20776795,"url":"https://github.com/phpactor/worse-reflection","last_synced_at":"2025-04-18T16:18:50.510Z","repository":{"id":16499458,"uuid":"80062468","full_name":"phpactor/worse-reflection","owner":"phpactor","description":"Surprisingly good for a bad static analyser. ","archived":false,"fork":false,"pushed_at":"2024-08-09T07:27:59.000Z","size":2011,"stargazers_count":21,"open_issues_count":6,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T06:33:20.078Z","etag":null,"topics":[],"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/phpactor.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":"2017-01-25T22:04:30.000Z","updated_at":"2025-01-14T12:51:45.000Z","dependencies_parsed_at":"2024-02-07T12:28:45.588Z","dependency_job_id":"7185e4fd-31d5-48b0-9daa-91a3bf7ab370","html_url":"https://github.com/phpactor/worse-reflection","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpactor%2Fworse-reflection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpactor%2Fworse-reflection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpactor%2Fworse-reflection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpactor%2Fworse-reflection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpactor","download_url":"https://codeload.github.com/phpactor/worse-reflection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249517772,"owners_count":21284836,"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-17T13:11:52.788Z","updated_at":"2025-04-18T16:18:50.489Z","avatar_url":"https://github.com/phpactor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Worse Reflection\n================\n\n\u003e This package is not actively developed here but in the main\n\u003e [phpactor](https://github.com/phpactor/phpactor) repository. It is\n\u003e _occasionally_ updated. Raise any issues about this repository there.\n\nThis library aims to provide a light class-based AST based \"reflection\" library.\n\n## Worse than Better\n\nIt is influenced by [BetterReflection](https://github.com/Roave/BetterReflection), diffrerences are as follows:\n\n- Can reflect variables.\n- Does not aim to implement built-in PHP reflection API.\n- Uses the amazing [Tolerant Parser](https://github.com/Microsoft/tolerant-php-parser).\n- Uses the PHPStorm stubs to provide reflections of internal classes.\n\nIt is being developed to provide support for the\n[Phpactor](https://github.com/dantleech/phpactor) introspection and\nrefactoring tool. And is therefore driven by that use case.\n\nIf you want comprehsnsive reflection, use BetterReflection. If you want faster\nreflection including type/value flow with no support and frequent BC breaks, then you can\nuse this one (note that I havn't benchmarked BR in sometime, it may well be faster now).\n\n## Usage\n\n```php\n$reflector = ReflectorBuilder::create()\n    -\u003eaddSource('\u003c?php ...')\n    -\u003ebuild();\n\n$class = $reflector-\u003ereflectClass('Foobar');\n\n$class-\u003emethods()-\u003eget('foobar')-\u003evisiblity()    == Visibility::public();\n$class-\u003eproperties()-\u003eget('barbar')-\u003evisiblity() == Visibility::public();\n\n/** @var ReflectionMethod */\nforeach ($class-\u003emethods() as $method) {\n    echo $method-\u003ename();                                  // methodName\n    echo $method-\u003ereturnType()-\u003eshort();                   // Foobar\n    echo (string) $method-\u003ereturnType();                   // This\\Is\\Foobar\n    echo (string) $method-\u003einferredReturnTypes()-\u003ebest(); // from docblock if it exists\n\n    foreach ($method-\u003eparameters() as $parameter) {\n        $parameter-\u003ename();                      // paramName\n        (string) $parameter-\u003einferredType();     // Fully\\Qualified\\ParamType\n    }\n\n}\n\nforeach ($class-\u003etraits() as $trait) {\n    // ...\n}\n\nforeach ($class-\u003einterfaes() as $interface) {\n    // ...\n}\n\nforeach ($class-\u003emethod('foobar')-\u003eframe()-\u003elocals() as $variable) {\n    $variable-\u003eoffset()-\u003etoInt(); // byte offset\n    $variable-\u003etype();            // variable type (if available )\n    $variable-\u003evalue();           // variable value (if available)\n}\n\n$offset = $reflection-\u003ereflectOffset(\n    SourceCode::fromString('...'), \n    Offset::fromInt(1234)\n);\n\n$offset-\u003evalue()-\u003etype();    // type at offset (if available)\n$offset-\u003evalue()-\u003evalue();   // value (e.g. 1234)\n$offset-\u003eframe();            // return frame\n```\n\nSee tests for more examples...\n\nContributing\n------------\n\nThis package is open source and welcomes contributions! Feel free to open a\npull request on this repository.\n\nSupport\n-------\n\n- Create an issue on the main [Phpactor](https://github.com/phpactor/phpactor) repository.\n- Join the `#phpactor` channel on the Slack [Symfony Devs](https://symfony.com/slack-invite) channel.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpactor%2Fworse-reflection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpactor%2Fworse-reflection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpactor%2Fworse-reflection/lists"}