{"id":13805649,"url":"https://github.com/phpstan/phpdoc-parser","last_synced_at":"2025-05-16T01:02:56.896Z","repository":{"id":37773868,"uuid":"111290081","full_name":"phpstan/phpdoc-parser","owner":"phpstan","description":"Next-gen phpDoc parser with support for intersection types and generics","archived":false,"fork":false,"pushed_at":"2025-04-15T15:31:19.000Z","size":973,"stargazers_count":1432,"open_issues_count":14,"forks_count":64,"subscribers_count":7,"default_branch":"2.1.x","last_synced_at":"2025-05-09T00:55:02.154Z","etag":null,"topics":["php","php7","phpdoc","phpstan","static-analysis","static-analyzer","static-code-analysis","testing"],"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/phpstan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2017-11-19T11:48:19.000Z","updated_at":"2025-05-06T08:14:36.000Z","dependencies_parsed_at":"2024-04-14T01:49:29.689Z","dependency_job_id":"cef4888e-5f98-4d6d-ad36-049788715c5d","html_url":"https://github.com/phpstan/phpdoc-parser","commit_stats":{"total_commits":426,"total_committers":49,"mean_commits":8.693877551020408,"dds":0.5375586854460094,"last_synced_commit":"54b191f409690206aed725a1c43fb450e499d4e0"},"previous_names":[],"tags_count":104,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpstan%2Fphpdoc-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpstan%2Fphpdoc-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpstan%2Fphpdoc-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpstan%2Fphpdoc-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpstan","download_url":"https://codeload.github.com/phpstan/phpdoc-parser/tar.gz/refs/heads/2.1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254423357,"owners_count":22068791,"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":["php","php7","phpdoc","phpstan","static-analysis","static-analyzer","static-code-analysis","testing"],"created_at":"2024-08-04T01:01:03.410Z","updated_at":"2025-05-16T01:02:56.844Z","avatar_url":"https://github.com/phpstan.png","language":"PHP","readme":"\u003ch1 align=\"center\"\u003ePHPDoc Parser for PHPStan\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://github.com/phpstan/phpdoc-parser/actions\"\u003e\u003cimg src=\"https://github.com/phpstan/phpdoc-parser/workflows/Build/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://packagist.org/packages/phpstan/phpdoc-parser\"\u003e\u003cimg src=\"https://poser.pugx.org/phpstan/phpdoc-parser/v/stable\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://choosealicense.com/licenses/mit/\"\u003e\u003cimg src=\"https://poser.pugx.org/phpstan/phpstan/license\" alt=\"License\"\u003e\u003c/a\u003e\n\t\u003ca href=\"https://phpstan.org/\"\u003e\u003cimg src=\"https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat\" alt=\"PHPStan Enabled\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nThis library `phpstan/phpdoc-parser` represents PHPDocs with an AST (Abstract Syntax Tree). It supports parsing and modifying PHPDocs.\n\nFor the complete list of supported PHPDoc features check out PHPStan documentation. PHPStan is the main (but not the only) user of this library.\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* [phpdoc-parser API Reference](https://phpstan.github.io/phpdoc-parser/2.1.x/namespace-PHPStan.PhpDocParser.html) with all the AST node types etc.\n\nThis parser also supports parsing [Doctrine Annotations](https://github.com/doctrine/annotations). The AST nodes live in the [PHPStan\\PhpDocParser\\Ast\\PhpDoc\\Doctrine namespace](https://phpstan.github.io/phpdoc-parser/2.1.x/namespace-PHPStan.PhpDocParser.Ast.PhpDoc.Doctrine.html).\n\n## Installation\n\n```\ncomposer require phpstan/phpdoc-parser\n```\n\n## Basic usage\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse PHPStan\\PhpDocParser\\Ast\\PhpDoc\\ParamTagValueNode;\nuse PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocNode;\nuse PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode;\nuse PHPStan\\PhpDocParser\\Lexer\\Lexer;\nuse PHPStan\\PhpDocParser\\ParserConfig;\nuse PHPStan\\PhpDocParser\\Parser\\ConstExprParser;\nuse PHPStan\\PhpDocParser\\Parser\\PhpDocParser;\nuse PHPStan\\PhpDocParser\\Parser\\TokenIterator;\nuse PHPStan\\PhpDocParser\\Parser\\TypeParser;\n\n// basic setup\n\n$config = new ParserConfig(usedAttributes: []);\n$lexer = new Lexer($config);\n$constExprParser = new ConstExprParser($config);\n$typeParser = new TypeParser($config, $constExprParser);\n$phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser);\n\n// parsing and reading a PHPDoc string\n\n$tokens = new TokenIterator($lexer-\u003etokenize('/** @param Lorem $a */'));\n$phpDocNode = $phpDocParser-\u003eparse($tokens); // PhpDocNode\n$paramTags = $phpDocNode-\u003egetParamTagValues(); // ParamTagValueNode[]\necho $paramTags[0]-\u003eparameterName; // '$a'\necho $paramTags[0]-\u003etype; // IdentifierTypeNode - 'Lorem'\n```\n\n### Format-preserving printer\n\nThis component can be used to modify the AST\nand print it again as close as possible to the original.\n\nIt's heavily inspired by format-preserving printer component in [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser).\n\n```php\n\u003c?php\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse PHPStan\\PhpDocParser\\Ast\\NodeTraverser;\nuse PHPStan\\PhpDocParser\\Ast\\NodeVisitor\\CloningVisitor;\nuse PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocNode;\nuse PHPStan\\PhpDocParser\\Ast\\Type\\IdentifierTypeNode;\nuse PHPStan\\PhpDocParser\\Lexer\\Lexer;\nuse PHPStan\\PhpDocParser\\ParserConfig;\nuse PHPStan\\PhpDocParser\\Parser\\ConstExprParser;\nuse PHPStan\\PhpDocParser\\Parser\\PhpDocParser;\nuse PHPStan\\PhpDocParser\\Parser\\TokenIterator;\nuse PHPStan\\PhpDocParser\\Parser\\TypeParser;\nuse PHPStan\\PhpDocParser\\Printer\\Printer;\n\n// basic setup with enabled required lexer attributes\n\n$config = new ParserConfig(usedAttributes: ['lines' =\u003e true, 'indexes' =\u003e true, 'comments' =\u003e true]);\n$lexer = new Lexer($config);\n$constExprParser = new ConstExprParser($config);\n$typeParser = new TypeParser($config, $constExprParser);\n$phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser);\n\n$tokens = new TokenIterator($lexer-\u003etokenize('/** @param Lorem $a */'));\n$phpDocNode = $phpDocParser-\u003eparse($tokens); // PhpDocNode\n\n$cloningTraverser = new NodeTraverser([new CloningVisitor()]);\n\n/** @var PhpDocNode $newPhpDocNode */\n[$newPhpDocNode] = $cloningTraverser-\u003etraverse([$phpDocNode]);\n\n// change something in $newPhpDocNode\n$newPhpDocNode-\u003egetParamTagValues()[0]-\u003etype = new IdentifierTypeNode('Ipsum');\n\n// print changed PHPDoc\n$printer = new Printer();\n$newPhpDoc = $printer-\u003eprintFormatPreserving($newPhpDocNode, $phpDocNode, $tokens);\necho $newPhpDoc; // '/** @param Ipsum $a */'\n```\n\n## Code of Conduct\n\nThis project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project and its community, you are expected to uphold this code.\n\n## Building\n\nInitially you need to run `composer install`, or `composer update` in case you aren't working in a folder which was built before.\n\nAfterwards you can either run the whole build including linting and coding standards using\n\n    make\n\nor run only tests using\n\n    make tests\n","funding_links":[],"categories":["PHP","Table of Contents"],"sub_categories":["Static Analysis","PHP - Docblock Parser"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpstan%2Fphpdoc-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpstan%2Fphpdoc-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpstan%2Fphpdoc-parser/lists"}