{"id":21771161,"url":"https://github.com/rightcapitalhq/phpdoc-parser","last_synced_at":"2025-04-13T16:41:21.513Z","repository":{"id":193244643,"uuid":"682428747","full_name":"RightCapitalHQ/phpdoc-parser","owner":"RightCapitalHQ","description":"Next-gen PHPDoc parser with support for intersection types and generics(TypeScript version)","archived":false,"fork":false,"pushed_at":"2025-04-07T23:37:39.000Z","size":1911,"stargazers_count":20,"open_issues_count":3,"forks_count":1,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-08T15:52:33.259Z","etag":null,"topics":["ast","javascript","parser","php","php7","phpdoc","phpdoc-parser","phpstan","rightcapital","static-analy","static-analyzer","static-code-analyzer","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/RightCapitalHQ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.json","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-24T06:38:27.000Z","updated_at":"2025-04-07T23:37:42.000Z","dependencies_parsed_at":"2023-11-08T05:38:22.468Z","dependency_job_id":"c5aca100-2b34-46ee-9b1b-d8705e02fec4","html_url":"https://github.com/RightCapitalHQ/phpdoc-parser","commit_stats":null,"previous_names":["rightcapitalhq/phpdoc-parser"],"tags_count":172,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphpdoc-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphpdoc-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphpdoc-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphpdoc-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RightCapitalHQ","download_url":"https://codeload.github.com/RightCapitalHQ/phpdoc-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248747061,"owners_count":21155382,"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":["ast","javascript","parser","php","php7","phpdoc","phpdoc-parser","phpstan","rightcapital","static-analy","static-analyzer","static-code-analyzer","typescript"],"created_at":"2024-11-26T14:15:15.300Z","updated_at":"2025-04-13T16:41:21.491Z","avatar_url":"https://github.com/RightCapitalHQ.png","language":"TypeScript","readme":"# PHPDoc parser TypeScript version\n\n\u003c!-- Badges area start --\u003e\n\n[![made by RightCapital](https://img.shields.io/badge/made_by-RightCapital-5070e6)](https://rightcapital.com)\n![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/RightCapitalHQ/phpdoc-parser/ci.yml)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits\u0026logoColor=white)](https://conventionalcommits.org)\n[![RightCapital frontend style guide](https://img.shields.io/badge/code_style-RightCapital-5c4c64?labelColor=f0ede8)](https://github.com/RightCapitalHQ/frontend-style-guide)\n\n\u003c!-- Badges area end --\u003e\n\nNext-gen PHPDoc parser with support for intersection types and generics(TypeScript version)\n\n## What's that\n\nThis parser is inspired by the PHPStan's phpdoc-parser library: https://github.com/phpstan/phpdoc-parser\n\nThis library `@rightcapital/phpdoc-parser` represents PHPDocs with an AST (Abstract Syntax Tree). It supports parsing and modifying PHPDocs by using `TypeScript`/`JavaScript`.\n\nFor the complete list of supported PHPDoc features check out PHPStan documentation.\n\n- [PHPDoc Basics](https://phpstan.org/writing-php-code/phpdocs-basics) (list of PHPDoc tags)\n- [PHPDoc Types](https://phpstan.org/writing-php-code/phpdoc-types) (list of PHPDoc types)\n\n## Installation\n\n```bash\n# pnpm\npnpm add @rightcapital/phpdoc-parser\n# yarn\nyarn add @rightcapital/phpdoc-parser\n# npm\nnpm install --save @rightcapital/phpdoc-parser\n```\n\n## Basic usage\n\n```typescript\nimport {\n  ConstExprParser,\n  Lexer,\n  PhpDocParser,\n  TokenIterator,\n  TypeParser,\n} from '@rightcapital/phpdoc-parser';\n\n// basic setup\n\nconst lexer = new Lexer();\nconst constExprParser = new ConstExprParser();\nconst typeParser = new TypeParser(constExprParser);\nconst phpDocParser = new PhpDocParser(typeParser, constExprParser);\n\n// parsing and reading a PHPDoc string\n\nconst tokens = new TokenIterator(lexer.tokenize('/** @param Lorem $a */'));\nconst phpDocNode = phpDocParser.parse(tokens); // PhpDocNode\nconst paramTags = phpDocNode.getParamTagValues(); // ParamTagValueNode[]\nconsole.log(paramTags[0].parameterName); // '$a'\nconsole.log(paramTags[0].type); // IdentifierTypeNode { attributes: {}, name: 'Lorem' }\n```\n\n## Format-preserving printer\n\nThis component can be used to modify the AST and print it again as close as possible to the original.\n\nIt's heavily inspired by format-preserving printer component in nikic/PHP-Parser.\n\n```typescript\nimport {\n  CloningVisitor,\n  ConstExprParser,\n  IdentifierTypeNode,\n  Lexer,\n  NodeTraverser,\n  PhpDocNode,\n  PhpDocParser,\n  TokenIterator,\n  TypeParser,\n  Printer,\n} from '@rightcapital/phpdoc-parser';\n\nconst usedAttributes = { lines: true, indexes: true };\n\nconst lexer = new Lexer();\nconst constExprParser = new ConstExprParser(true, true, usedAttributes);\nconst typeParser = new TypeParser(constExprParser, true, usedAttributes);\nconst phpDocParser = new PhpDocParser(\n  typeParser,\n  constExprParser,\n  true,\n  true,\n  usedAttributes,\n);\n\nconst tokens = new TokenIterator(lexer.tokenize('/** @param Lorem $a */'));\nconst phpDocNode = phpDocParser.parse(tokens); // PhpDocNode\n\nconst cloningTraverser = new NodeTraverser([new CloningVisitor()]);\n\nconst [newPhpDocNode] = cloningTraverser.traverse([phpDocNode]) as [PhpDocNode];\n\n// change something in newPhpDocNode\nnewPhpDocNode.getParamTagValues()[0].type = new IdentifierTypeNode('Ipsum');\n\n// print changed PHPDoc\nconst printer = new Printer();\nconst newPhpDoc = printer.print(newPhpDocNode);\nconsole.log(newPhpDoc);\n// --- result ---\n// /**\n//  * @param Ipsum $a\n//  */\n\nconst newPhpDocWithFormatPreserving = printer.printFormatPreserving(\n  newPhpDocNode,\n  phpDocNode,\n  tokens,\n);\nconsole.log(newPhpDocWithFormatPreserving); // '/** @param Ipsum $a */'\n```\n\n## Welcome to contribute\n\nWe are stilling waiting for someones to contribute, especially for the following features.\n\n- Doctrine Annotations support\n- More tests\n- More docs\n- A script to monitor [upstream](https://github.com/phpstan/phpdoc-parser) updates and notify the author to catch up.\n\nPlease check out our [Contribution guide](docs/CONTRIBUTING.md)\n\n## How did we create the initial version of this project.\n\nWe created most of our code by using ChatGPT as a tool to transform most code from https://github.com/phpstan/phpdoc-parser to TypeScript version.\n\nOur PHP API haven't used Doctrine, so Doctrine support are removed.\n\n## License\n\nMIT License © 2023-Present\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightcapitalhq%2Fphpdoc-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frightcapitalhq%2Fphpdoc-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightcapitalhq%2Fphpdoc-parser/lists"}