Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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);
}
}
```