bulton-fr/methods-header-generator

Generate the header of all methods into a PHP classes.

0.1.2 2018-08-17 00:00 UTC

This package is auto-updated.

Last update: 2024-11-28 23:33:48 UTC


README

Generate methods struct for all classes of a project. Can be used like help to write documentation.

Build Status Scrutinizer Code Quality Latest Stable Version License

Install

With composer composer require bulton-fr/methods-header-generator

Because dependency phpdocumentor/reflection-common in 2.0.0-beta1, you should have PHP >= 7.1

I will see if I can doing anything to allow PHP 5.x versions.

Use it

With ProjectParser class

This class will take all classes declared into your composer project, and inspect her. The other function of this class is to save all class already parsed to avoid to re-parse it again if another class extend it (for exemple).

About composer, it should have the classmap generated. So you should use the option -o when you install or update your composer project.

Exemple : composer update -o

To use ProjectParser :

$project = new \bultonFr\MethodsHeaderGenerator\ProjectParser('myVendorPath', ['myNamespaceToInspect\\']);
echo $project->run();

The constructor take three parameters:

  • $vendorDir The path to the vendor dir
  • $nsToParse An array of all namespace to parse
  • $nsToIgnore An array of all namespace to ignore

Exemple with my BFW project: I create the file : /docs/parser.php

<?php

$autoload = require_once(__DIR__.'/../vendor/autoload.php');

$project = new \bultonFr\MethodsHeaderGenerator\ProjectParser(
    __DIR__.'/../vendor',
    'BFW\\',
    'BFW\\Test\\'
);
echo $project->run();

I ask to ProjectParse to generate the structure for classes with a namespace started by \BFW\, but to ignore all classes with a namespace who started by \BFW\Test to not have my unit test classes inspected.

Without ProjectParser class

Without ProjectParser, you will loop on all your classes manually. For each class, you will instantiate ClassParser and take him the class name you want to inspect, with the namespace.

Exemple:

$parser = new \bultonFr\MethodsHeaderGenerator\ClassParser('myClass');
echo $parser->run();

What is returned ?

If I use ClassParser on the class ProjectParser, it will return :

bultonFr\MethodsHeaderGenerator\ProjectParser
self public __construct(string $vendorDir, string[]|string $nsToParse, [string[]|string $nsToIgnore=array()])
void public addToClasses(\bultonFr\MethodsHeaderGenerator\ClassParser $parser)
\bultonFr\MethodsHeaderGenerator\ClassParser[] public getClasses()
\bultonFr\MethodsHeaderGenerator\ClassParser public getClassesByName(string $className)
\Composer\Autoload\ClassLoader|null public getComposerLoader()
string[] public getNsToIgnore()
string[] public getNsToParse()
string public getVendorDir()
bool public hasClasses(string $className)
bool protected isIgnoredNS(string $className)
void protected obtainClassList()
void protected obtainComposerLoader()
string public run()