Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deprecated-packages/betterphpdocparser
[DEPRECATED] Moved to
https://github.com/deprecated-packages/betterphpdocparser
format-preserving-printer php phpdoc phpdoc-parser phpstan wrapper
Last synced: about 1 month ago
JSON representation
[DEPRECATED] Moved to
- Host: GitHub
- URL: https://github.com/deprecated-packages/betterphpdocparser
- Owner: deprecated-packages
- License: mit
- Created: 2018-04-24T12:31:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-05T23:26:42.000Z (almost 6 years ago)
- Last Synced: 2024-12-02T06:07:17.605Z (about 2 months ago)
- Topics: format-preserving-printer, php, phpdoc, phpdoc-parser, phpstan, wrapper
- Language: PHP
- Homepage: https://github.com/rectorphp/rector
- Size: 166 KB
- Stars: 43
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Deprecated, moved to Rector](https://github.com/rectorphp/rector)
# Better PhpDoc Parser
[![Build Status](https://img.shields.io/travis/Symplify/BetterPhpDocParser/master.svg?style=flat-square)](https://travis-ci.org/Symplify/BetterPhpDocParser)
[![Downloads](https://img.shields.io/packagist/dt/symplify/better-phpdoc-parser.svg?style=flat-square)](https://packagist.org/packages/symplify/better-phpdoc-parser/stats)Wrapper around [phpstan/phpdoc-parser](https://github.com/phpstan/phpdoc-parser) that adds **format preserving printer**.
## When do We Need Format Preserving Printer?
**Original code**
```php
/**
* @param string $name
* @param string $surname
* @return bool
*/
```**Printed by PHPStan PhpDocParser** :x:
```php
/**
* @param string $name
* @param string $surname
* @return bool
*/
```**Printed by Better PhpDocParser** :+1:
```php
/**
* @param string $name
* @param string $surname
* @return bool
*/
```[Symplify\CodingStandard](https://github.com/symplify/codingstandard) and [Rector](https://github.com/rectorphp/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`](https://github.com/nikic/PHP-Parser/issues/487).
## Install
```bash
composer require symplify/better-phpdoc-parser
```## Usage
Register services in your Symfony config:
```yaml
# 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
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);
}
}
```