symplify / better-phpdoc-parser
This package is abandoned and no longer maintained.
The author suggests using the rector/rector package instead.
Slim wrapper around phpstan/phpdoc-parser with format preserving printer
v5.4.16
2019-03-05 23:15 UTC
Requires
- php: ^7.1
- nette/utils: ^2.5
- phpstan/phpdoc-parser: ^0.3.1
- symplify/package-builder: ^5.4.16
Requires (Dev)
- phpunit/phpunit: ^7.5|^8.0
- dev-master / 5.5.x-dev
- v5.4.16
- v5.4.15
- v5.4.14
- v5.4.13
- v5.4.12
- v5.4.11
- v5.4.10
- v5.4.9
- v5.4.8
- v5.4.7
- v5.4.6
- v5.4.5
- v5.4.4
- v5.4.3
- v5.4.2
- v5.4.1
- v5.4.0
- v5.3.12
- v5.3.11
- v5.3.10
- v5.3.9
- v5.3.8
- v5.3.7
- v5.3.6
- v5.3.5
- v5.3.4
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.22
- v5.2.20
- v5.2.19
- v5.2.18
- v5.2.17
- v5.2.16
- v5.2.15
- v5.2.14
- v5.2.13
- v5.2.12
- v5.2.11
- v5.2.10
- v5.2.9
- v5.2.8
- v5.2.7
- v5.2.6
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2.0
- v5.1.4
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.2
- v5.0.1
- v5.0.0
- v4.8.0
- v4.7.0
- v4.6.1
- v4.6.0
- v4.5.1
- v4.5.0
- v4.4.2
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.2
- v4.1.1
- v4.1.0
This package is auto-updated.
Last update: 2019-10-12 17:29:03 UTC
README
Better PhpDoc Parser
Wrapper around phpstan/phpdoc-parser that adds format preserving printer.
When do We Need Format Preserving Printer?
Original code
/** * @param string $name * @param string $surname * @return bool */
Printed by PHPStan PhpDocParser ❌
/** * @param string $name * @param string $surname * @return bool */
Printed by Better PhpDocParser 👍
/** * @param string $name * @param string $surname * @return bool */
Symplify\CodingStandard and Rector need to modify docblock and put it back in correct format. Other packages often put own spacing, or formats of specific tags.
This package preserve original spacing.
Thanks for inspiration in Format Preserving Printer feature in nikic/php-parser
.
Install
composer require symplify/better-phpdoc-parser
Usage
Register services in your Symfony config:
# services.yaml imports: - { resource: 'vendor/symplify/better-phpdoc-parser/config/config.yml' }
or register the needed services from services.yaml
in config of your other framework.
<?php use Symplify\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Symplify\BetterPhpDocParser\Printer\PhpDocInfoPrinter; class SomeClass { public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpDocInfoPrinter $phpDocInfoPrinter) { $this->phpDocInfoFactory = $phpDocInfoFactory; $this->phpDocInfoPrinter = $phpDocInfoPrinter; } public function changeDocBlockAndPrintItBack(): string { $docComment = '/** @var Type $variable */'; $phpDocInfo = $this->phpDocInfoFactory->createFrom($docComment); // modify `$phpDocInfo` using its methods return $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo); } }