.. _phpdoc_guide: ############################## PHPDoc Guide for Doxygen Usage ############################## This guide explains how to properly document PHP code using PHPDoc comments and generate documentation using `Doxygen `_. .. contents:: Table of Contents :local: :depth: 2 ---------------------- Introduction to PHPDoc ---------------------- PHPDoc is a standardized way of documenting PHP code using special comment blocks (`/** ... */`). Doxygen can parse these comments to generate structured documentation. **Basic Example:** .. code-block:: php `` * - ``@version`` - Specifies version information - ``@version 1.0.0`` * - ``@since`` - Indicates when a feature was added - ``@since 2.0`` --------------------------- Documenting Classes & Files --------------------------- **Documenting a Class** .. code-block:: php name = $name; } /** * Gets the user's name. * * @return string The name of the user. */ public function getName(): string { return $this->name; } } ------------------------- Generating Documentation ------------------------- To generate documentation using Doxygen: 1. **Install Doxygen**: Download from `https://www.doxygen.nl/` and install it. 2. **Create a Doxygen configuration file**: Run: .. code-block:: bash doxygen -g Doxyfile 3. **Modify the `Doxyfile`**: - Set `INPUT` to the PHP source code directory. - Enable `EXTRACT_ALL = YES` to parse all comments. - Set `FILE_PATTERNS = *.php` to only parse PHP files. 4. **Generate the Documentation**: .. code-block:: bash doxygen Doxyfile 5. **View the Output**: - Open `html/index.html` in a browser. ----------------- Best Practices ----------------- - **Use meaningful descriptions**: Avoid generic comments. - **Keep comments up-to-date**: Maintain consistency with code changes. - **Use proper data types**: Always specify accurate types (`int`, `string`, `array`, etc.). - **Be concise but informative**: Don’t over-explain obvious things. - **Always generate comments above your methods**: Even if the method simply return void. ----------------- Conclusion ----------------- Using PHPDoc correctly helps create clean, well-documented code. With Doxygen, you can turn comments into structured, browsable documentation. For more details, refer to: - `Doxygen PHP Support `_ - `PHPDoc Standard `_