PHPackages                             jasny/phpdoc-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jasny/phpdoc-parser

ActiveLibrary

jasny/phpdoc-parser
===================

Jasny skeleton library

v1.0.1(2y ago)41343.5k—7%8[2 issues](https://github.com/jasny/phpdoc-parser/issues)8MITPHPPHP &gt;=7.4.0

Since Jan 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jasny/phpdoc-parser)[ Packagist](https://packagist.org/packages/jasny/phpdoc-parser)[ RSS](/packages/jasny-phpdoc-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (8)

[![jasny-banner](https://user-images.githubusercontent.com/100821/62123924-4c501c80-b2c9-11e9-9677-2ebc21d9b713.png)](https://user-images.githubusercontent.com/100821/62123924-4c501c80-b2c9-11e9-9677-2ebc21d9b713.png)

Jasny PHPDoc parser
===================

[](#jasny-phpdoc-parser)

[![Build status](https://github.com/jasny/phpdoc-parser/actions/workflows/php.yml/badge.svg)](https://github.com/jasny/phpdoc-parser/actions/workflows/php.yml)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/06441737de8fff6e79a8ff3b3107aa3f48bffa4bde6e1fa2d4ef327e5dbce105/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f706870646f632d7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jasny/phpdoc-parser/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/e7451a9827c5ba64cdd65918ee26471d5914578b929fef00b14d1c2ec77e71f8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f706870646f632d7061727365722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jasny/phpdoc-parser/?branch=master)[![Packagist Stable Version](https://camo.githubusercontent.com/8b0c16cb1f16b81cb33874501629ec8e7911a8a9f743e2e4691627c76507e4c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a61736e792f706870646f632d7061727365722e737667)](https://packagist.org/packages/jasny/phpdoc-parser)[![Packagist License](https://camo.githubusercontent.com/775871d8372466104aeff2755a9b7447e5e79de7235a48790d4b7de37393ac75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a61736e792f706870646f632d7061727365722e737667)](https://packagist.org/packages/jasny/phpdoc-parser)

Configurable DocBlock parser from PHP.

The PHPDoc parser allows you to configure tags including the method how to parse and extract information. This is inline with phpDocumentor style annotations and differs from for instance Doctrine type annotations.

Installation
------------

[](#installation)

```
composer require jasny/phpdoc-parser

```

Usage
-----

[](#usage)

```
/**
 * The description of foo. This function does a lot of thing
 *   which are described here.
 *
 * Some more text here.
 *
 * @important
 * @uses FooReader
 * @internal Why this isn't part of the API.
 *   Multi-line is supported.
 *
 * @param string|callable $first   This is the first param
 * @param int             $second  The second one
 * @return void
 * @throws InvalidArgumentException
 * @throws DoaminException if first argument is not found
 */
function foo($first, int $second)
{
   // ...
}
```

Parse annotations

```
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
use Jasny\PhpdocParser\Tag\FlagTag;

$doc = (new ReflectionFunction('foo'))->getDocComment();

$customTags = [
    new FlagTag('important')
];
$tags = PhpDocumentor::tags()->with($customTags);

$parser = new PhpdocParser($tags);
$meta = $parser->parse($doc);
```

The result will be the following:

```
[
    'summery' => "The description of foo",
    'description' => "The description of foo. This function does a lot of thing which are described here.\n\nSome more text.",
    'important' => true,
    'uses' => 'FooReader',
    'internal' => "Why this isn't part of the API. Mutlti-line is supported",
    'params' => [
        'first' => [
            'type' => "string|callable",
            'name' => "first",
            'description' => "This is the first parm"
        ],
        'second' => [
            'type' => "int",
            'name' => "second",
        ]
    ],
    'return' => 'void'
]
```

Tags
----

[](#tags)

The following tags are included in `PhpDocumentor::tags()`:

- `@api`
- `@author`
- `@copyright`
- `@deprecated`
- `@example`
- `@ignore`
- `@internal`
- `@link`
- `@method` (all methods will be grouped in `methods` array)
- `@package`
- `@param` (all params will be grouped in `params` array)
- `@property` (all properties will be grouped in `properties` array)
- `@property-read` (also in `properties` array)
- `@property-write` (also in `properties` array)
- `@return`
- `@see`
- `@since`
- `@throws` (all exceptions will be grouped in `throws` array)
- `@todo`
- `@uses`
- `@used-by`
- `@var`

If you only need to parse those tags, you can simply do:

```
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;

//$doc = ...; Get doc-comment string from reflection

$tags = PhpDocumentor::tags();
$parser = new PhpdocParser($tags);
$meta = $parser->parse($doc);
```

Tags classes
------------

[](#tags-classes)

Here's a list of available tags classes:

- [Summery](https://www.jasny.net/phpdoc-parser/tags/summery)
- [ArrayTag](https://www.jasny.net/phpdoc-parser/tags/array)
- [CustomTag](https://www.jasny.net/phpdoc-parser/tags/custom)
- [DescriptionTag](https://www.jasny.net/phpdoc-parser/tags/description)
- [ExampleTag](https://www.jasny.net/phpdoc-parser/tags/example)
- [FlagTag](https://www.jasny.net/phpdoc-parser/tags/flag)
- [MapTag](https://www.jasny.net/phpdoc-parser/tags/map)
- [MethodTag](https://www.jasny.net/phpdoc-parser/tags/method)
- [ModifyTag](https://www.jasny.net/phpdoc-parser/tags/modify)
- [MultiTag](https://www.jasny.net/phpdoc-parser/tags/multi)
- [NumberTag](https://www.jasny.net/phpdoc-parser/tags/number)
- [RegExpTag](https://www.jasny.net/phpdoc-parser/tags/regexp)
- [VarTag](https://www.jasny.net/phpdoc-parser/tags/var)
- [WordTag](https://www.jasny.net/phpdoc-parser/tags/word)

FQSEN Resolver
--------------

[](#fqsen-resolver)

FQSEN stands for `Fully Qualified Structural Element Name`. FQSEN convertor is used to expand class name or function name to fully unique name (so with full namespace). For example, `Foo` can be converted to `Zoo\\Foo\\Bar`.

Such convertors are used in this lib. Some tags, that deal with variable types, or classes names, support adding them as a constructor parameter.

For example, `TypeTag`, that can be used for parsing `@return` tag, has the following constructor: `TypeTag($name, $fqsenConvertor = null)`. If provided, convertor expands the type, given as type of returned value in doc-comment. If ommited, the type will stay as it is in doc-comment.

Convertor can be provided in one of two ways:

- `$tags = PhpDocumentor::tags($fn)` - for all the tags, predefined in `PhpDocumentor::tags()`
- `$tags = $tags->add(new TypeTag('footag', $fn))` - for all the tags, that are explicitly added to predefined, it should be passed as a constructor parameter (if it is supported by constructor).

After that create the parser from the tags as `$parser = new PhpdocParser($tags)`.

The resolver function should accept a class name and return an expanded name.

### Example

[](#example)

This example uses [phpDocumentor/TypeResolver](https://github.com/phpDocumentor/TypeResolver).

```
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
use phpDocumentor\Reflection\Types\ContextFactory;
use phpDocumentor\Reflection\FqsenResolver;

$reflection = new ReflectionClass('\My\Example\Classy');

$contextFactory = new ContextFactory();
$context = $contextFactory->createFromReflector($reflection);

$resolver = new FqsenResolver();
$fn = fn(string $class): string => $resolver->resolve($class, $context);

$tags = PhpDocumentor::tags($fn);
$parser = new PhpdocParser($tags);

$doc = $reflection->getDocComment();
$meta = $parser->parse($doc);
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~519 days

Total

2

Last Release

1074d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (57 commits)")[![Minstel](https://avatars.githubusercontent.com/u/6154708?v=4)](https://github.com/Minstel "Minstel (50 commits)")[![NekoOs](https://avatars.githubusercontent.com/u/14964692?v=4)](https://github.com/NekoOs "NekoOs (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jasny-phpdoc-parser/health.svg)

```
[![Health](https://phpackages.com/badges/jasny-phpdoc-parser/health.svg)](https://phpackages.com/packages/jasny-phpdoc-parser)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
