|
1 | 1 | ## DocBlocks |
2 | 2 |
|
3 | | -@TODO - Entend information about DocBlocks specific to the Framework and CMS. Other project? |
| 3 | +Documentation headers for PHP code in: files, classes, class properties, methods and functions, called the docblocks, follow a convention similar to JavaDoc or phpDOC. |
| 4 | + |
| 5 | +These "DocBlocks" borrow from the PEAR standard but have some variations specific for Joomla and the Joomla projects. |
| 6 | + |
| 7 | +Whereas normal code indenting uses real tabs, all whitespace in a Docblock uses real spaces. This provides better readability in source code browsers. The minimum whitespace between any text elements, such as tags, variable types, variable names and tag descriptions, is two real spaces. Variable types and tag descriptions should be aligned according to the longest Docblock tag and type-plus-variable respectively. |
| 8 | + |
| 9 | +Code contributed to the Joomla project that will become the copyright of the project is not allowed to include @author tags. You should update the contribution log in CREDITS.php. Joomla's philosophy is that the code is written "all together" and there is no notion of any one person "owning" any section of code. The @author tags are permitted in third-party libraries that are included in the core libraries. |
| 10 | + |
| 11 | +Files included from third party sources must leave DocBlocks intact. Layout files use the same DocBlocks as other PHP files. |
| 12 | + |
| 13 | +### File DocBlock Headers |
| 14 | +The file header DocBlock consists of the following required and optional elements in the following order: |
| 15 | +Short description (optional unless the file contains more than two classes or functions), followed by a blank line). Long description (optional, followed by a blank line). |
| 16 | + |
| 17 | +* @category (optional and rarely used) |
| 18 | +* @package (generally optional but required when files contain only procedural code) |
| 19 | +* @subpackage (optional) |
| 20 | +* @author (optional but only permitted in non-Joomla source files, for example, included third-party libraries like Geshi) |
| 21 | +* @copyright (required) |
| 22 | +* @license (required and must be compatible with the Joomla license) |
| 23 | +* @deprecated (optional) |
| 24 | +* @link (optional) |
| 25 | +* @see (optional) |
| 26 | +* @since (generally optional but required when files contain only procedural code) |
| 27 | + |
| 28 | +Example of a DocBlock Header: |
| 29 | + |
| 30 | +```php |
| 31 | +/** |
| 32 | + * @package Joomla.Installation |
| 33 | + * @subpackage Controller |
| 34 | + * |
| 35 | + * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. |
| 36 | + * @license GNU General Public License version 2 or later; see LICENSE.txt |
| 37 | + */ |
| 38 | +``` |
| 39 | + |
| 40 | +### Class Definitions |
| 41 | +Class definitions start on a new line and the opening and closing braces are also placed on new lines. Class methods must follow the guidelines for Function Definitions. Properties and methods must follow OOP standards and be declared appropriately (using public, protected, private and static as applicable). |
| 42 | +Class definitions, properties and methods must each be provided with a DocBlock in accordance with the following sections. |
| 43 | + |
| 44 | +#### Class DocBlock Headers |
| 45 | +The class Docblock consists of the following required and optional elements in the fol-lowing order. |
| 46 | +Short description (required, unless the file contains more than two classes or functions), followed by a blank line). Long description (optional, followed by a blank line). |
| 47 | +* @category (optional and rarely used) |
| 48 | +* @package (required) |
| 49 | +* @subpackage (optional) |
| 50 | +* @author (optional but only permitted in non-Joomla source files, for example, included third-party libraries like Geshi) |
| 51 | +* @copyright (optional unless different from the file Docblock) |
| 52 | +* @license (optional unless different from the file Docblock) |
| 53 | +* @deprecated (optional) |
| 54 | +* @link (optional) |
| 55 | +* @see (optional) |
| 56 | +* @since (required, being the version of the software the class was introduced) |
| 57 | + |
| 58 | +Example of a Class file DocBlock header: |
| 59 | +```php |
| 60 | +/** |
| 61 | + * Controller class to initialise the database for the Joomla Installer. |
| 62 | + * |
| 63 | + * @package Joomla.Installation |
| 64 | + * @subpackage Controller |
| 65 | + * @since 3.1 |
| 66 | + */ |
| 67 | +``` |
| 68 | + |
| 69 | +#### Class Property DocBlocks |
| 70 | +The class property Docblock consists of the following required and optional elements in the following order. |
| 71 | +Short description (required, followed by a blank line) |
| 72 | + |
| 73 | +* @var (required, followed by the property type) |
| 74 | +* @deprecated (optional) |
| 75 | +* @since (required) |
| 76 | + |
| 77 | +Example of Class property DocBlock: |
| 78 | + |
| 79 | +```php |
| 80 | + /** |
| 81 | + * The generated user ID |
| 82 | + * |
| 83 | + * @var integer |
| 84 | + * @since 3.1 |
| 85 | + */ |
| 86 | + protected static $userId = 0; |
| 87 | +``` |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +#### Class Method DocBlocks and Functions DocBlocks |
| 92 | +Function definitions start on a new line and the opening and closing braces are also placed on new lines. An empty line should precede lines specifying the return value. |
| 93 | + |
| 94 | +Function definitions must include a documentation comment in accordance with the Commenting section of this document. |
| 95 | + |
| 96 | +* Short description (required, followed by a blank line) |
| 97 | +* Long description (optional, followed by a blank line) |
| 98 | +* @param (required if there are method or function arguments, the last @param tag is followed by a blank line) |
| 99 | +* @return (required, followed by a blank line) |
| 100 | +* All other tags in alphabetical order, however @since is always required. |
| 101 | + |
| 102 | +Example of Method DocBlock: |
| 103 | +```php |
| 104 | + /** |
| 105 | + * Set a controller class suffix for a given HTTP method. |
| 106 | + * |
| 107 | + * @package Joomla.Framework |
| 108 | + * @subpackage Router |
| 109 | + * |
| 110 | + * |
| 111 | + * @param string $method The HTTP method for which to set the class suffix. |
| 112 | + * @param string $suffix The class suffix to use when fetching the controller name for a given request. |
| 113 | + * |
| 114 | + * @return Router Returns itself to support chaining. |
| 115 | + * |
| 116 | + * @since 1.0 |
| 117 | + */ |
| 118 | + public function setHttpMethodSuffix($method, $suffix) |
| 119 | +``` |
| 120 | + |
| 121 | +If a function definition goes over multiple lines, all lines must be indented with one tab and the closing brace must go on the same line as the last parameter. |
| 122 | + |
| 123 | +```php |
| 124 | +function fooBar($param1, $param2, |
| 125 | + $param3, $param4) |
| 126 | +{ |
| 127 | + // Body of method. |
| 128 | +} |
| 129 | +``` |
0 commit comments