rector/packages/simple-php-doc-parser
Tomas Votruba a7705ed0a5
[Symplify 9] First update + switch to RuleDocGenerator (#4616)
* [composer] bump to Symplify 9

* [Symplify 9] Update phpstan rules

* bump to Symplify 9 BETA2

* update AbstractKernel from Tests to Testing namespace

* decoupling removing node trait

* remove fluent calls

* removing variadic

* [CodingStyle] Improve AnnotateThrowablesRector

* bump deps

* Make use of RuleDocGenerator

* first short

* [DocumentationGenerator] Drop deprecated package, RuleSetGenerator now handles it

* import namespace

* update docs
2020-11-16 17:50:38 +00:00
..
2020-10-12 21:44:10 +02:00

Simple PHP Doc Parser

Simple service integration of phpstan/phpdoc-parser, with few extra goodies for practical use

1. Install

composer require rector/simple-php-doc-parser

2. Register Bundle

Register bundle in your project:

// app/bundles.php
return [
    Rector\SimplePhpDocParser\Bundle\SimplePhpDocParserBundle::class => [
        'all' => true,
    ],
];

or via Kernel:

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Rector\SimplePhpDocParser\Bundle\SimplePhpDocParserBundle;

final class AppKernel extends Kernel
{
    /**
     * @return BundleInterface[]
     */
    public function registerBundles(): array
    {
        return [new SimplePhpDocParserBundle()];
    }
}

3. Usage

Required services Rector\SimplePhpDocParser\SimplePhpDocParser in constructor, where you need it, and use it:

use Rector\SimplePhpDocParser\SimplePhpDocParser;

final class SomeClass
{
    /**
     * @var SimplePhpDocParser
     */
    private $simplePhpDocParser;

    public function __construct(SimplePhpDocParser $simplePhpDocParser)
    {
        $this->simplePhpDocParser = $simplePhpDocParser;
    }

    public function some()
    {
        $docBlock = '/** @param int $name */';

        /** @var \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode $phpDocNode */
        $phpDocNode = $this->simplePhpDocParser->parseDocBlock($docBlock);

        // param extras

        /** @var \PHPStan\PhpDocParser\Ast\Type\TypeNode $nameParamType */
        $nameParamType = $phpDocNode->getParamType('name');

        /** @var \PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode $nameParamTagValueNode */
        $nameParamTagValueNode = $phpDocNode->getParam('name');
    }
}