Generate documentation for PHP Code using phpDocumentor

What is phpDocumentor?
phpDocumentor is the simple and best tool to generate API documentation for PHP source code. 


Downloading & installing phpDocumentor:
There are several dependencies to install phpDocumentor you can find them on official website i.e., here

To install phpDocumentor using PEAR type below command
  • In windows, run command prompt as administrator. Goto xampp/php folder and type
    pear channel-discover pear.phpdoc.org
    pear install phpdoc/phpDocumentor
  • In linux, open terminal and type (if install xampp for linux then goto xampp/bin folder)
    pear channel-discover pear.phpdoc.org
    pear install phpdoc/phpDocumentor
Generate API using phpDocumentor:
  • In windows, goto  phpdoc.bat folder and run phpdoc  command for source directory to destination
     phpdoc -d <source directory of php code> -t <destination directory>
  • In Linux, goto [phpdocumentor installation folder]/bin/ and run command
     phpdoc -d <source directory of php> -t <destination directory>
Note:
If in case, installation method through PEAR gives you below error. Try downloading phar and proceed
Fatal error: Uncaught TypeError: Argument 1 passed to Monolog\ErrorHandler::handleException() must be an instance of Exception...

Download .phar from here
To generate API run the below command from php directory with the location of .phar file
php phpDocumentor.phar -d <source directory of php code> -t <destination directory>

If you find any error related to Graphviz, download and install software from here. Set the environment variable for Graphviz/bin directory for 'dot' executable file.