### Class Method/Function DocBlock Example Source: https://developer.joomla.org/coding-standards/docblocks Example of a class method or function DocBlock, detailing required elements like short description, @param, @return, @since, @throws, and optional long description. ```php /** * Set a controller class suffix for a given HTTP method. * * @param string $method The HTTP method for which to set the class suffix. * @param string $suffix The class suffix to use when fetching the controller name for a given request. * * @return JApplicationWebRouter This object for method chaining. * * @since 12.2 * * @throws InvalidArgumentException Thrown if the provided arguments is not of type string. * @throws \UnexpectedValueException May be thrown if the container has not been set. */ public function setHttpMethodSuffix($method, $suffix) ``` -------------------------------- ### Joomla Class Definition Example Source: https://developer.joomla.org/coding-standards/php-code Demonstrates the standard structure for defining a class in Joomla, including DocBlocks for the class, properties, and methods. It follows specific Joomla conventions for package, subpackage, and versioning. ```php /** * A utility class. * * @package Joomla.Platform * @subpackage XBase * @since 1.6 */ class JClass extends JObject { /** * Human readable name * * @var string * @since 1.6 */ public $name; /** * Method to get the name of the class. * * @param string $case Optionally return in upper/lower case. * * @return boolean True if successfully loaded, false otherwise. * * @since 1.6 */ public function getName($case = null) { // Body of method. return $this->name; } } ``` -------------------------------- ### PHP File DocBlock Header Example Source: https://developer.joomla.org/coding-standards/docblocks Example of a standard DocBlock header for PHP files in Joomla projects. It includes essential tags like @package, @copyright, and @license, following specific formatting rules for clarity and consistency. ```PHP /** * @package Joomla.Installation * @subpackage Controller * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ ``` -------------------------------- ### Class Property DocBlock Example Source: https://developer.joomla.org/coding-standards/docblocks Example of a required and optional elements for a class property DocBlock, including short description, @var, @since, and @deprecated tags. ```php /** * The generated user ID * * @var integer * @since 3.1 */ protected static $userId = 0; ``` -------------------------------- ### Joomla Namespace and Use Statement Example Source: https://developer.joomla.org/coding-standards/php-code Shows the standard structure for namespaces and import statements in Joomla files, including file DocBlocks, namespace declaration, defined check, and alphabetically ordered 'use' statements. ```php /** * @package Joomla.Administrator * @subpackage mod_quickicon * * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Module\Quickicon\Administrator\Helper; defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Router\Route; use Joomla\Module\Quickicon\Administrator\Event\QuickIconsEvent; ``` -------------------------------- ### PHP Class DocBlock Header Example Source: https://developer.joomla.org/coding-standards/docblocks Example of a DocBlock header for PHP classes in Joomla projects. It details required and optional tags such as @package, @subpackage, and @since, adhering to Joomla's coding standards for class documentation. ```PHP /** * Controller class to initialise the database for the Joomla Installer. * * @package Joomla.Installation * @subpackage Controller * @since 3.1 */ ``` -------------------------------- ### Joomla JS Variable Naming Example Source: https://developer.joomla.org/coding-standards/javascript-j3 Demonstrates the Joomla JavaScript coding standard for variable declaration, emphasizing descriptive names and camel case. This follows the convention of using `likeThis` for variables. ```javascript var element = document.getElementById('elementId'); ``` -------------------------------- ### Run PHP_CodeSniffer using Ant Source: https://developer.joomla.org/coding-standards/analysis If Ant is installed, this command provides a simpler way to run the PHP_CodeSniffer with Joomla standards. Navigate to the project's root directory and execute this command to initiate the code analysis. ```shell ant phpcs ``` -------------------------------- ### Joomla! Coding Standards Overview Source: https://developer.joomla.org/coding-standards/html Overview of the Joomla! coding standards, covering various aspects from basic guidelines to specific language syntaxes. It references external style guides and provides links to related documentation. ```APIDOC Joomla! Coding Standards: Introduction: https://developer.joomla.org/coding-standards/introduction.html Source Code Management: https://developer.joomla.org/coding-standards/source-code-management.html License: https://developer.joomla.org/coding-standards/license.html Coding Standards Sections: Basic Guidelines: https://developer.joomla.org/coding-standards/basic-guidelines.html Inline Code Comments: https://developer.joomla.org/coding-standards/inline-code-comments.html DocBlocks: https://developer.joomla.org/coding-standards/docblocks.html PHP Code: https://developer.joomla.org/coding-standards/php-code.html XML: https://developer.joomla.org/coding-standards/xml.html INI: https://developer.joomla.org/coding-standards/ini.html Client Side Syntax Style Guides: HTML: https://developer.joomla.org/coding-standards/html.html CSS: https://developer.joomla.org/coding-standards/css.html JavaScript - Joomla 3.x: https://developer.joomla.org/coding-standards/javascript-j3.html JavaScript - Joomla 4.x: https://developer.joomla.org/coding-standards/javascript.html SCSS: https://developer.joomla.org/coding-standards/scss.html Appendices: Analysis: https://developer.joomla.org/coding-standards/analysis.html Examples: https://developer.joomla.org/coding-standards/examples.html Influences: Google's HTML styleguide jQuery's HTML Styleguide Nicolas Ghallager's 'Principles of writing consistent, idiomatic HTML' Harry Robert's 'My HTML/CSS coding style' BBC's Media Standards and Guidelines ``` -------------------------------- ### Joomla JS Function Naming Example Source: https://developer.joomla.org/coding-standards/javascript-j3 Illustrates the Joomla JavaScript coding standard for function declaration, requiring names that clearly describe the function's purpose and using camel case. ```javascript function getSomeData() { // statements } ``` -------------------------------- ### Joomla! Coding Standards Overview Source: https://developer.joomla.org/coding-standards/.html Overview of the Joomla! coding standards, covering various aspects from basic guidelines to specific language syntaxes. It references external style guides and provides links to related documentation. ```APIDOC Joomla! Coding Standards: Introduction: https://developer.joomla.org/coding-standards/introduction.html Source Code Management: https://developer.joomla.org/coding-standards/source-code-management.html License: https://developer.joomla.org/coding-standards/license.html Coding Standards Sections: Basic Guidelines: https://developer.joomla.org/coding-standards/basic-guidelines.html Inline Code Comments: https://developer.joomla.org/coding-standards/inline-code-comments.html DocBlocks: https://developer.joomla.org/coding-standards/docblocks.html PHP Code: https://developer.joomla.org/coding-standards/php-code.html XML: https://developer.joomla.org/coding-standards/xml.html INI: https://developer.joomla.org/coding-standards/ini.html Client Side Syntax Style Guides: HTML: https://developer.joomla.org/coding-standards/html.html CSS: https://developer.joomla.org/coding-standards/css.html JavaScript - Joomla 3.x: https://developer.joomla.org/coding-standards/javascript-j3.html JavaScript - Joomla 4.x: https://developer.joomla.org/coding-standards/javascript.html SCSS: https://developer.joomla.org/coding-standards/scss.html Appendices: Analysis: https://developer.joomla.org/coding-standards/analysis.html Examples: https://developer.joomla.org/coding-standards/examples.html Influences: Google's HTML styleguide jQuery's HTML Styleguide Nicolas Ghallager's 'Principles of writing consistent, idiomatic HTML' Harry Robert's 'My HTML/CSS coding style' BBC's Media Standards and Guidelines ``` -------------------------------- ### Joomla Coding Standards Overview Source: https://developer.joomla.org/coding-standards/inline-code-comments Details the various coding standards and style guides followed by the Joomla project for different languages and file types. This ensures consistency and maintainability across the codebase. ```APIDOC Joomla Coding Standards: - Introduction: https://developer.joomla.org/coding-standards/introduction.html - Source Code Management: https://developer.joomla.org/coding-standards/source-code-management.html - License: https://developer.joomla.org/coding-standards/license.html - Basic Guidelines: https://developer.joomla.org/coding-standards/basic-guidelines.html - Inline Code Comments: https://developer.joomla.org/coding-standards/inline-code-comments.html - DocBlocks: https://developer.joomla.org/coding-standards/docblocks.html - PHP Code: https://developer.joomla.org/coding-standards/php-code.html - XML: https://developer.joomla.org/coding-standards/xml.html - INI: https://developer.joomla.org/coding-standards/ini.html - HTML: https://developer.joomla.org/coding-standards/html.html - CSS: https://developer.joomla.org/coding-standards/css.html - JavaScript (Joomla 3.x): https://developer.joomla.org/coding-standards/javascript-j3.html - JavaScript (Joomla 4.x): https://developer.joomla.org/coding-standards/javascript.html - SCSS: https://developer.joomla.org/coding-standards/scss.html ``` -------------------------------- ### JavaScript Comment Styles Source: https://developer.joomla.org/coding-standards/javascript-j3 Details the correct formatting for single-line and multi-line comments in JavaScript. Single-line comments should start with `// ` and be placed above the relevant code. Multi-line comments require an opening `/*`, a blank line, then `** ` for each comment line, followed by a closing `*/`. ```javascript // I am a single line comment. /* ** I am a multiline comment. ** Line two ** Line three */ ``` -------------------------------- ### Chaining Select Array and Type Casting Example Source: https://developer.joomla.org/coding-standards/php-code Demonstrates building a database query using Joomla!'s database query builder. It shows how to select specific fields, specify the table, filter records by user ID with integer type casting, and order the results. ```php $query = $db->getQuery(true) ->select(array( $db->quoteName('profile_key'), $db->quoteName('profile_value'), )) ->from($db->quoteName('#__user_profiles')) ->where($db->quoteName('user_id') . ' = ' . (int) $userId) ->order($db->quoteName('ordering')); ``` -------------------------------- ### PHP Comment Formatting Example Source: https://developer.joomla.org/coding-standards/inline-code-comments Demonstrates the correct placement and formatting of inline comments in PHP code according to Joomla standards. Comments should precede the code they refer to, be on their own lines, and align with the code's indentation. ```PHP while (!$done) { // We don't want an infinite loop here. $done = true; } // Now let's do something interesting. $result = somethingInteresting(); ``` -------------------------------- ### PHP Function Definition Structure Source: https://developer.joomla.org/coding-standards/php-code Function definitions in PHP must start on a new line, with no space between the function name and the opening parenthesis. Opening and closing braces should be on their own lines. A documentation comment (DocBlock) is mandatory. ```php /** * A utility function. * * @param string $path The library path in dot notation. * * @return void * * @since 1.6 */ function jimport($path) { // Body of method. } ``` ```php function fooBar($param1, $param2, $param3, $param4) { // Body of method. } ``` -------------------------------- ### JavaScript Type Checking Source: https://developer.joomla.org/coding-standards/javascript-j3 Provides examples of common type checking methods in JavaScript, including using the `typeof` operator for primitive types and jQuery's utility functions for more complex checks like plain objects, functions, and arrays. ```javascript // String: typeof object === 'string' // Number: typeof object === 'number' // Boolean: typeof object === 'boolean' // Object: typeof object === 'object' // Plain Object: jQuery.isPlainObject( object ) // Function: jQuery.isFunction( object ) // Array: jQuery.isArray( object ) // Element: object.nodeType // null: object === null // null or undefined: object == null // Undefined: // Global Variables: typeof variable === 'undefined' // Local Variables: variable === undefined // Properties: object.prop === undefined ``` -------------------------------- ### Trailing Whitespace Removal Source: https://developer.joomla.org/coding-standards/.html Illustrates the importance of removing trailing whitespace from lines to prevent complications in code diffs and maintain clean code. Shows examples of correct and incorrect trailing whitespace. ```html
Yes please.
No, thank you.
``` -------------------------------- ### Joomla! SCSS Zero Value Units Source: https://developer.joomla.org/coding-standards/scss Instructs developers to omit units for zero values in CSS properties. For example, 'padding: 0;' is preferred over 'padding: 0px;'. ```CSS // Good .example { padding: 0; } // Bad - uses units .example { padding: 0px; } ``` -------------------------------- ### Trailing Whitespace Removal Source: https://developer.joomla.org/coding-standards/html Illustrates the importance of removing trailing whitespace from lines to prevent complications in code diffs and maintain clean code. Shows examples of correct and incorrect trailing whitespace. ```htmlYes please.
No, thank you.
``` -------------------------------- ### PHP Control Structures Formatting (Mixed Language) Source: https://developer.joomla.org/coding-standards/php-code Demonstrates the use of alternative syntax for control structures within mixed PHP and HTML files (e.g., layout files), ensuring each block is properly enclosed in `` tags. ```PHP ``` -------------------------------- ### PHP Control Structures Formatting (General) Source: https://developer.joomla.org/coding-standards/php-code Defines the standard formatting for PHP control structures, including spacing around keywords and parentheses, brace placement on new lines, and indentation rules for multi-line conditions. ```PHP if ($test) { echo 'True'; } // Note that "elseif" as one word is used. elseif ($test === false) { echo 'Really false'; } elseif (!$condition) { echo 'Not Condition'; } else { echo 'A white lie'; } ``` ```PHP if ($test1 && $test2) { echo 'True'; } ``` ```PHP do { $i++; } while ($i < 10); ``` ```PHP for ($i = 0; $i < $n; $i++) { echo 'Increment = ' . $i; } ``` ```PHP foreach ($rows as $index => $row) { echo 'Index = ' . $index . ', Value = ' . $row; } ``` ```PHP while (!$done) { $done = true; } ``` ```PHP switch ($value) { case 'a': echo 'A'; break; default: echo 'I give up'; break; } ``` ```PHP try { $table->bind($data); } catch (RuntimeException $e) { throw new Exception($e->getMessage(), 500, $e); } ``` -------------------------------- ### Marking TODO Items Source: https://developer.joomla.org/coding-standards/.html Recommends highlighting tasks or notes for future implementation using the `TODO` keyword within HTML comments. This makes it easy to track pending work or areas needing attention. ```html` must not be omitted. Always include the closing tag for clarity and strict HTML compliance. ```html
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Joomla Private Class Members and Properties Source: https://developer.joomla.org/coding-standards/php-code Illustrates the convention for private and protected class members in Joomla, including the use of a leading underscore for private members and underscore_format for protected properties. ```php class JFooHelper { protected $field_name = null; private $_status = null; protected function sort() { // Code goes here } } ``` -------------------------------- ### Joomla! CSS Comment Styles Source: https://developer.joomla.org/coding-standards/css Demonstrates different comment styles used in Joomla! CSS, including standard block comments, Doxygen-style comments for detailed documentation, and single-line comments for preprocessors like LESS/SCSS. ```php /* Mobile navigation ========================================================================== */ ``` ```php /** * Short description using Doxygen-style comment format * * The first sentence of the long description starts here and continues on this * line for a while finally concluding here at the end of this paragraph. * * The long description is ideal for more detailed explanations and * documentation. It can include example HTML, URLs, or any other information * that is deemed necessary or useful. * * @tag This is a tag named 'tag' * * TODO: This is a todo statement that describes an atomic task to be completed * at a later date. It wraps after 80 characters and following lines are * indented by 2 spaces. */ ``` ```php /* Basic comment */ ``` ```php // These are stripped on compile. ``` -------------------------------- ### Basic Comments Source: https://developer.joomla.org/coding-standards/scss Provides the standard format for basic inline comments within code. ```text // Basic comment ``` -------------------------------- ### HTML Attribute Order Source: https://developer.joomla.org/coding-standards/.html Attributes should be ordered to prioritize CSS and JavaScript selectors. The recommended order is `class`, `id`, `data-*`, followed by all other attributes. ```html Text Text ``` -------------------------------- ### HTML Optional Closing Tags Source: https://developer.joomla.org/coding-standards/html Optional closing tags for elements like `
` must not be omitted. Always include the closing tag for clarity and strict HTML compliance. ```html
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog. ``` -------------------------------- ### Joomla! CSS Alignment Standards Source: https://developer.joomla.org/coding-standards/css Explains the required alignment for CSS braces and properties. The opening brace should be on the same line as the selector, preceded by a space, and the closing brace should be on its own line, aligned with the opening brace. ```css /* Good */ .example { color: #fff; } ``` ```css /* Bad - closing brace is in the wrong place */ .example { color: #fff; } ``` ```css /* Bad - opening brace missing space */ .example{ color: #fff; } ``` -------------------------------- ### HTML Attribute Order Source: https://developer.joomla.org/coding-standards/html Attributes should be ordered to prioritize CSS and JavaScript selectors. The recommended order is `class`, `id`, `data-*`, followed by all other attributes. ```html Text Text ``` -------------------------------- ### HTML Formatting: Whitespace and Structure Source: https://developer.joomla.org/coding-standards/html Demonstrates correct use of new lines and indentation for HTML elements like divs, lists, and tables to enhance readability. Encourages ample whitespace between blocks and consistent indentation. ```html
Space, the final frontier.
| Income | Taxes |
|---|---|
| $ 5.00 | $ 4.50 |
Space, the final frontier.
| Income | Taxes |
|---|---|
| $ 5.00 | $ 4.50 |
```
--------------------------------
### Joomla JS Multiple Variable Declarations
Source: https://developer.joomla.org/coding-standards/javascript-j3
Shows the standard Joomla JavaScript style for declaring multiple variables using a single `var` statement, with each variable on a new line and separated by commas.
```javascript
var foo = 'bar',
bar = 'baz',
baz = 'qux';
```
--------------------------------
### Style Attributes and Semantics
Source: https://developer.joomla.org/coding-standards/.html
Advises against using deprecated HTML attributes like `border`, `align`, `valign`, or `clear`. It also stresses the importance of using HTML elements according to their semantic purpose for accessibility and code efficiency.
```html
View subscriptions