Docblock Type Normalizer
Homepage: https://github.com/mfn/php-docblock-normalize, (*1)
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., (*2)
Requirements
PHP 5.6, (*3)
Install
Using composer: composer.phar require mfn/docblock-normalize 0.1
, (*4)
Example
sample.php
:, (*5)
<?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:, (*6)
$parser = new \Mfn\DocblockNormalize\Parser(
new \Mfn\DocblockNormalize\TokenParser
);
$docblocks = $parser->parseFile('sample.php');
echo $docblocks[0]->getNormalizedContent();
Will return:, (*7)
/**
* @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!, (*8)
Note 2: the normalization also removes leading backslashes, this is expected!, (*9)
Contribute
Fork it, hack on a feature branch, create a pull request, be awesome!, (*10)
No developer is an island so adhere to these standards:, (*11)
© Markus Fischer markus@fischer.name, (*12)