{"id":21771169,"url":"https://github.com/rightcapitalhq/php-parser","last_synced_at":"2025-04-13T16:41:18.953Z","repository":{"id":194734579,"uuid":"682428980","full_name":"RightCapitalHQ/php-parser","owner":"RightCapitalHQ","description":"TypeScript types for PHP Parser JSON representation","archived":false,"fork":false,"pushed_at":"2025-04-08T02:12:06.000Z","size":785,"stargazers_count":3,"open_issues_count":5,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-11T22:11:38.344Z","etag":null,"topics":["ast","parser","php","php-parser","phpparser","static-analysis","static-analyzer","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@rightcapital/php-parser","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":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-08-24T06:39:04.000Z","updated_at":"2025-04-07T21:44:01.000Z","dependencies_parsed_at":"2023-09-27T19:12:12.831Z","dependency_job_id":"dda1f0f4-f23f-4656-a688-b33be30e0b3b","html_url":"https://github.com/RightCapitalHQ/php-parser","commit_stats":null,"previous_names":["rightcapitalhq/php-parser"],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphp-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphp-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphp-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RightCapitalHQ%2Fphp-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RightCapitalHQ","download_url":"https://codeload.github.com/RightCapitalHQ/php-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248747043,"owners_count":21155376,"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","parser","php","php-parser","phpparser","static-analysis","static-analyzer","typescript"],"created_at":"2024-11-26T14:15:16.608Z","updated_at":"2025-04-13T16:41:18.934Z","avatar_url":"https://github.com/RightCapitalHQ.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript types for PHP Parser JSON representation\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/php-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\n# Introduction\n\nThis NPM package is focusing on providing to following abilities:\n\n- A TypeScript/JavaScript wrapper for calling nikic's PHP-Parser\n- Sort of auto generated type definitions to annotate the AST (represented as JSON) from nikic's PHP-Parser cli\n- Some util/helper functions to easily retrieving proper PHP AST node with correct type annotation\n\n# Installation\n\nThis package needs you have PHP with composer installed first\n\n```bash\n# pnpm\npnpm add @rightcapital/php-parser\n# yarn\nyarn add @rightcapital/php-parser\n# npm\nnpm install --save @rightcapital/php-parser\n```\n\n# Basic Usage\n\nSupposed you have a PHP file named `hello.php` with the following content\n\n```php\n \u003c?php\necho \"Hello\";\n```\n\nHere is your TypeScript code for parsing and retrieving the AST nodes of the above PHP file.\n\n```typescript\nimport {\n  CliHelpers,\n  FullyQualifiedScalarString,\n  FullyQualifiedStmtEcho,\n  NodeRetrieverHelpers,\n  NodeType,\n  NodeTypeInheritingFromNodeAbstract,\n} from '@rightcapital/php-parser';\n\n// Get the root AST nodes from PHP file\nconst rootNodes: NodeTypeInheritingFromNodeAbstract[] =\n  CliHelpers.parsePhpFileToAst('./hello.php');\n// or if you prefer to get AST from code string, just use\n// CliHelpers.parsePhpCodeStringToAst(`\u003c?php echo \"Hello\";`)\n\nconsole.log(rootNodes);\n// [\n//   {\n//     nodeType: \"Stmt_Echo\",\n//     attributes: { startLine: 2, startFilePos: 6, endLine: 2, endTokenPos: 4, endFilePos: 18 },\n//     exprs: [[Object]],\n//   },\n// ];\n\nconst echoNode =\n  NodeRetrieverHelpers.findNodeByNodeType\u003cFullyQualifiedStmtEcho\u003e(\n    rootNodes,\n    NodeType.Stmt_Echo,\n  );\n\n// Get the specified node with type annotation\nconsole.log(echoNode);\n// {\n//   nodeType: 'Stmt_Echo',\n//   attributes: { startLine: 2, startFilePos: 6, endLine: 2, endTokenPos: 4, endFilePos: 18 },\n//   exprs: [\n//     { nodeType: 'Scalar_String', attributes: [Object], value: 'Hello' }\n//   ]\n// }\n\nconst scalarStringNode =\n  NodeRetrieverHelpers.findNodeByNodeType\u003cFullyQualifiedScalarString\u003e(\n    echoNode!.exprs,\n    NodeType.Scalar_String,\n  );\nconsole.log(scalarStringNode?.value);\n// Hello\n```\n\n## License\n\nMIT License © 2023-Present\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightcapitalhq%2Fphp-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frightcapitalhq%2Fphp-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightcapitalhq%2Fphp-parser/lists"}