mfn/docblock-normalize

Extracts doc blocks and normalizes the references classes based on the current namespace and use-aliases

0.1 2015-11-21 11:26 UTC

This package is auto-updated.

Last update: 2024-10-16 16:53:51 UTC


README

Homepage: https://github.com/mfn/php-docblock-normalize

Blurb

This library extracts docblocks from source files and normalizes all type descriptions within. That is, they're turned into full qualified symbol names taking the current namespace and use-aliases into consideration.

Requirements

PHP 5.6

Install

Using composer: composer.phar require mfn/docblock-normalize 0.1

Example

sample.php:

<?php namespace Foo;
use Bar as Baz;
/**
 * @param Foo $param1
 * @param Bar $param2
 * @param Baz $param3
 * @param \Foo $param4
 * @param string $param5
 */

Parse and output the docblock with its types normalized:

$parser = new \Mfn\DocblockNormalize\Parser(
    new \Mfn\DocblockNormalize\TokenParser
);

$docblocks = $parser->parseFile('sample.php');

echo $docblocks[0]->getNormalizedContent();

Will return:

/**
 * @param Foo\Foo $param1
 * @param Foo\Bar $param2
 * @param Bar $param3
 * @param Foo $param4
 * @param string $param5
 */

Note: namespace and use statements for the docblock must appear before it!

Note 2: the normalization also removes leading backslashes, this is expected!

Contribute

Fork it, hack on a feature branch, create a pull request, be awesome!

No developer is an island so adhere to these standards:

© Markus Fischer markus@fischer.name