### 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. ```html

Yes 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 ``` -------------------------------- ### Joomla SQL Query Construction with JDatabaseQuery API Source: https://developer.joomla.org/coding-standards/php-code Demonstrates how to build SQL queries programmatically using the JDatabaseQuery API in Joomla. It covers obtaining the database connector, creating a query object, using query chaining for readability, and executing the query. Key methods like select, from, where, order, quoteName, quote, setQuery, and loadObjectList are illustrated. ```APIDOC Joomla Database Query API Usage: This API provides methods to construct SQL queries in a portable and secure manner, abstracting away database-specific syntax. Key Concepts: - **Database Connector**: Obtain via `JFactory::getDbo()`. - **Query Object**: Create using `$db->getQuery(true)`. - **Query Chaining**: Connect multiple query methods sequentially for improved readability and simplified code. - **Quoting**: Use `$db->quoteName()` for table and column names, and `$db->quote()` for field values to prevent SQL injection and ensure portability. - **Table Prefixes**: Always use the `#__` prefix for Joomla content tables, which is automatically replaced by the user-defined database prefix. Core Methods: - `select(string|array $fields)`: Specifies the fields to retrieve. Use `$db->quoteName()` for field names. - `from(string $table, string $alias = null)`: Specifies the table to query from. Use `$db->quoteName()` for table names. - `where(string $conditions)`: Adds WHERE clauses. Use `$db->quote()` for values and `$db->quoteName()` for column names. For integers, cast to `(int)`. - `order(string $column)`: Specifies the order of results. Use `$db->quoteName()` for column names. - `setQuery(JDatabaseQuery $query)`: Sets the query object to be executed by the database connector. - `loadObjectList(string $key = null, array $columns = null)`: Executes the query and returns results as an array of objects. Example 1: Basic Query Construction ```php // Get the database connector. $db = JFactory::getDbo(); // Get the query from the database connector. $query = $db->getQuery(true); // Build the query programmatically (example with chaining) // Note: You can use the qn alias for the quoteName method. $query->select($db->qn('u.*')) ->from($db->qn('#__users', 'u')); // Tell the database connector what query to run. $db->setQuery($query); // Invoke the query or data retrieval helper. $users = $db->loadObjectList(); ``` Example 2: Longer Chaining with Quoting and Conditions ```php // Using chaining when possible. $query->select($db->quoteName(array('user_id', 'profile_key', 'profile_value', 'ordering'))) ->from($db->quoteName('#__user_profiles')) ->where($db->quoteName('profile_key') . ' LIKE '. $db->quote(''custom.%'')) ->order('ordering ASC'); ``` Error Conditions: - Invalid SQL syntax will cause execution errors. - Missing database connection will prevent query execution. - Improper quoting can lead to SQL injection vulnerabilities or syntax errors. ``` -------------------------------- ### Multi-line Function Definition Formatting Source: https://developer.joomla.org/coding-standards/docblocks Illustrates the formatting for function definitions that span multiple lines, including indentation and placement of the closing brace. ```php function fooBar($param1, $param2, $param3, $param4) { // Body of method. } ``` -------------------------------- ### 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 ``` -------------------------------- ### File Inclusion Statements Source: https://developer.joomla.org/coding-standards/php-code Details the correct usage of `require_once` for unconditional file inclusion and `include_once` for conditional inclusion, emphasizing their statement nature and proper syntax. ```PHP require_once JPATH_COMPONENT . '/helpers/helper.php'; ``` ```PHP include_once JPATH_COMPONENT . '/helpers/conditional_helper.php'; ``` -------------------------------- ### Joomla JS Function Call Spacing Source: https://developer.joomla.org/coding-standards/javascript-j3 Demonstrates the standard Joomla JavaScript spacing for function calls, including single and multiple arguments. ```javascript foo( arg ); ``` ```javascript foo( 'string', object ); ``` -------------------------------- ### Run PHP_CodeSniffer with Joomla Standards Source: https://developer.joomla.org/coding-standards/analysis This command executes PHP_CodeSniffer with the Joomla coding standards, generating a checkstyle report. It requires specifying the report format, output file, the path to the Joomla standards directory, and the target directory for analysis. ```shell phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=/path/to//build/phpcs/Joomla /path/to/ ``` -------------------------------- ### Chaining Method Calls in JavaScript (jQuery) Source: https://developer.joomla.org/coding-standards/javascript-j3 Illustrates the practice of chaining method calls in JavaScript, commonly used with libraries like jQuery. This allows for a more concise and readable way to perform sequential operations on a selected element. ```javascript $('.someElement') .hide() .delay(1000) .fadeIn(); ``` -------------------------------- ### Joomla API Documentation Reference Source: https://developer.joomla.org/coding-standards/inline-code-comments Provides access to the official API documentation for the Joomla project. This is a crucial resource for developers working with Joomla's codebase or building extensions. ```APIDOC Joomla API Documentation: URL: https://api.joomla.org Description: Official API reference for the Joomla project, detailing classes, methods, functions, and their usage. Essential for developers building extensions or contributing to the core. Related Resources: - Developer Network: https://developer.joomla.org - Joomla Framework: https://framework.joomla.org - Issue Tracker: https://issues.joomla.org ``` -------------------------------- ### JavaScript Array Literal Syntax and Push Source: https://developer.joomla.org/coding-standards/javascript-j3 Recommends using array literal syntax (`[]`) instead of the `new Array()` constructor. If the array length is unknown, the `push()` method is advised to add elements, which replaces the current array content. ```javascript // No: var myArr = new Array(); // Yes: var myArr = []; // Using push when length is unknown: myArr.push('foo'); ``` -------------------------------- ### XML Empty Element Formatting Source: https://developer.joomla.org/coding-standards/xml Demonstrates the standard way to format empty XML elements in Joomla projects. Attributes like name, type, label, and description should be listed in order on separate lines. ```xml ``` -------------------------------- ### Joomla Exception Hierarchy Overview Source: https://developer.joomla.org/coding-standards/php-code Lists and describes various exceptions used within the Joomla framework. These exceptions categorize different types of errors, from invalid arguments and domain issues to runtime problems and unexpected values, aiding in robust error handling. ```APIDOC Joomla Exception Types: This section details the exception classes used for error reporting in Joomla. **General Exceptions**: - **BadMethodCallException**: Thrown when a callback refers to an undefined method or arguments are missing for magic call methods. - **InvalidArgumentException**: Thrown when input arguments are invalid. - **DomainException**: Thrown when a value does not adhere to a defined valid data domain (e.g., unsupported driver). - **LengthException**: Thrown when a length check on an argument fails (e.g., file signature length). - **OutOfRangeException**: Thrown when an illegal index is requested. **Runtime Exceptions**: These are thrown when external entities or environment issues cause problems beyond direct control, even with valid input. - **RuntimeException**: The default case for errors where the cause isn't explicitly determined (e.g., database server down, SQL query failure). - **UnexpectedValueException**: Used when a function call returns an unexpected result (e.g., string instead of boolean). - **OutOfBoundsException**: Thrown if a value is not a valid key. - **OverflowException**: Thrown when adding an element to a full container. - **RangeException**: Indicates range errors during execution, typically arithmetic errors other than under/overflow. This is the runtime version of DomainException. - **UnderflowException**: Thrown when attempting to remove an element from an empty container. **Documenting Exceptions**: - Use the `[@throws](https://github.com/throws)` tag in method/function annotations to specify thrown exception types. - Annotate any downstream exception types as well. - Each exception type needs to be annotated only once per function/method. ``` -------------------------------- ### Joomla JS Function Call with Object Argument Style Source: https://developer.joomla.org/coding-standards/javascript-j3 Shows the Joomla JavaScript coding standard for function calls where the first argument is an object, requiring no space before the opening brace. ```javascript foo({ a: 'bar', b: 'baz' }); ``` -------------------------------- ### HTML Minimal Versionless Doctype Source: https://developer.joomla.org/coding-standards/.html Specifies the document type for HTML5, ensuring modern browser rendering. Use the minimal, versionless doctype for consistency. ```html ``` -------------------------------- ### Joomla! API Documentation Source: https://developer.joomla.org/coding-standards/html Provides access to the official Joomla! API documentation, detailing available functions, classes, and methods for developers working with the Joomla! platform. ```APIDOC Joomla! API Documentation: Access the comprehensive API reference for Joomla! development. URL: https://api.joomla.org ``` -------------------------------- ### PHP Keywords and Constants Casing Source: https://developer.joomla.org/coding-standards/php-code Enforces the use of lowercase for all PHP keywords and constants like `true`, `false`, and `null`, adhering to PSR-2 coding style guidelines. ```PHP ``` -------------------------------- ### Joomla! API Documentation Source: https://developer.joomla.org/coding-standards/.html Provides access to the official Joomla! API documentation, detailing available functions, classes, and methods for developers working with the Joomla! platform. ```APIDOC Joomla! API Documentation: Access the comprehensive API reference for Joomla! development. URL: https://api.joomla.org ``` -------------------------------- ### Joomla! SCSS Indentation (2 Spaces) Source: https://developer.joomla.org/coding-standards/scss Illustrates the correct indentation for SCSS code, requiring exactly two spaces for each level of nesting. This ensures consistent code structure and readability across the project. ```CSS // Good .example { color: #000; visibility: hidden; } // Bad - using tabs or 4 spaces .example { color: #000; visibility: hidden; } ``` -------------------------------- ### Keyboard Navigation Access Key Source: https://developer.joomla.org/coding-standards/inline-code-comments Specifies the access key combination for keyboard navigation within the Joomla interface. This enhances accessibility for users who prefer keyboard interaction. ```APIDOC Keyboard Navigation: Access Key: Alt + 9 Description: Allows users to quickly navigate to specific sections or elements using keyboard shortcuts, improving efficiency and accessibility. ``` -------------------------------- ### Joomla! API Documentation Reference Source: https://developer.joomla.org/coding-standards/.html Reference to the official API documentation for Joomla! This entry serves as a pointer to the comprehensive API specifications, which are not embedded directly in this document. ```APIDOC API Documentation: URL: https://api.joomla.org Description: Comprehensive API specifications for Joomla! development. This includes details on endpoints, methods, parameters, and return values for interacting with Joomla! services. ``` -------------------------------- ### Joomla! API Documentation Reference Source: https://developer.joomla.org/coding-standards/html Reference to the official API documentation for Joomla! This entry serves as a pointer to the comprehensive API specifications, which are not embedded directly in this document. ```APIDOC API Documentation: URL: https://api.joomla.org Description: Comprehensive API specifications for Joomla! development. This includes details on endpoints, methods, parameters, and return values for interacting with Joomla! services. ``` -------------------------------- ### HTML Minimal Versionless Doctype Source: https://developer.joomla.org/coding-standards/html Specifies the document type for HTML5, ensuring modern browser rendering. Use the minimal, versionless doctype for consistency. ```html ``` -------------------------------- ### PHP Code Commenting Conventions Source: https://developer.joomla.org/coding-standards/php-code PHP files should use C-style block comments (`/* ... */`) for documentation headers and C++ style single-line comments (`// ...`) for code notes. Perl/shell style comments (`#`) are not permitted. Debugging comments should be removed before submission. ```php // Must fix this code up one day. //$code = broken($fixme); ``` -------------------------------- ### Joomla JS Function Call with Callback Argument Style Source: https://developer.joomla.org/coding-standards/javascript-j3 Illustrates the Joomla JavaScript coding standard for function calls with a callback as the last argument, showing required spacing. ```javascript foo( data, function() { // statements }); ``` -------------------------------- ### 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 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

  • Home
  • Blog
  • Home
  • Blog
``` ```html

Space, the final frontier.

  • Moe
  • Larry
  • Curly
Income Taxes
$ 5.00 $ 4.50
``` -------------------------------- ### HTML Element Structure Source: https://developer.joomla.org/coding-standards/html Always include the fundamental ``, ``, and `` tags to define the document structure. This is a standard requirement for valid HTML. ```html Page Title ``` -------------------------------- ### HTML Element Structure Source: https://developer.joomla.org/coding-standards/.html Always include the fundamental ``, ``, and `` tags to define the document structure. This is a standard requirement for valid HTML. ```html Page Title ``` -------------------------------- ### 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
  • Home
  • Blog
  • Home
  • Blog
``` ```html

Space, the final frontier.

  • Moe
  • Larry
  • Curly
Income Taxes
$ 5.00 $ 4.50
``` -------------------------------- ### Joomla! Statistics API Documentation Source: https://developer.joomla.org/coding-standards/html Details the API endpoints and data structures for retrieving Joomla! usage statistics, enabling developers to integrate statistical data into their applications. ```APIDOC Joomla! Statistics API: Provides access to usage statistics data. URL: https://developer.joomla.org/about/stats/api.html ``` -------------------------------- ### PHP Code Tags and Closing Tag Usage Source: https://developer.joomla.org/coding-standards/php-code Specifies the use of full `` tags for PHP code and advises against including the closing `?>` tag in files containing only PHP to prevent accidental output and errors. ```PHP ``` ```PHP // For files containing only PHP, omit the closing tag // This prevents trailing whitespace injection. // Files should end with a blank new line. ``` -------------------------------- ### Joomla! SCSS Brace Alignment Source: https://developer.joomla.org/coding-standards/scss Specifies the correct placement for opening and closing braces in SCSS. The opening brace must follow the selector on the same line with a preceding space, and the closing brace must be on its own line, aligned with the opening brace. ```CSS // Good .example { color: #fff; } // Bad - closing brace is in the wrong place .example { color: #fff; } // Bad - opening brace missing space .example{ color: #fff; } ``` -------------------------------- ### Joomla JS Array Declaration Style Source: https://developer.joomla.org/coding-standards/javascript-j3 Shows the standard Joomla JavaScript syntax for declaring arrays, including spacing around elements and the closing bracket. ```javascript var array = [ 'foo', 'bar' ]; ``` -------------------------------- ### Joomla! Statistics API Documentation Source: https://developer.joomla.org/coding-standards/.html Details the API endpoints and data structures for retrieving Joomla! usage statistics, enabling developers to integrate statistical data into their applications. ```APIDOC Joomla! Statistics API: Provides access to usage statistics data. URL: https://developer.joomla.org/about/stats/api.html ``` -------------------------------- ### Major Sections Commenting Source: https://developer.joomla.org/coding-standards/scss Defines the format for commenting major code sections. Sections should be named in uppercase and enclosed within a full comment block. ```text // Major comment // // Major comment description goes here // and continues here ``` -------------------------------- ### Joomla XML Field Definition with Radio Options Source: https://developer.joomla.org/coding-standards/xml Demonstrates the structure for defining a Joomla XML field, specifically a 'radio' type. It includes attributes like name, type, label, and description, along with nested option elements. ```XML ``` -------------------------------- ### PHP Global Variables Source: https://developer.joomla.org/coding-standards/php-code Recommends avoiding global variables in favor of static class properties or constants, aligning with Object-Oriented Programming principles and factory patterns for better code management. ```PHP // Avoid global variables like this: // $global_config = get_config(); // Instead, use static properties or constants within classes: class ConfigHelper { private static $config; public static function getConfig() { if (self::$config === null) { self::$config = self::loadConfig(); } return self::$config; } private static function loadConfig() { // Load configuration logic return ['setting' => 'value']; } } // Usage: $config = ConfigHelper::getConfig(); ``` -------------------------------- ### Sub Sections Commenting Source: https://developer.joomla.org/coding-standards/scss Defines the format for commenting sub-sections within code. Subsections should use normal casing and be enclosed within an open comment block. ```text // // Sub section comment // ``` -------------------------------- ### Image Tag Requirements Source: https://developer.joomla.org/coding-standards/.html Mandates that all image elements (``) must include an `alt` attribute. Height and width attributes are optional and can be omitted. ```html Joomla Logo ``` -------------------------------- ### 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
View subscriptions
``` -------------------------------- ### JavaScript Object Literal Syntax Source: https://developer.joomla.org/coding-standards/javascript-j3 Enforces the use of object literal syntax (`{}`) over the `new Object()` constructor for creating objects in JavaScript. For objects with multiple key/value pairs, each pair should be on a new line. ```javascript // No: var myObj = new Object(); // Yes: var myObj = {}; // With multiple key/value pairs: var myObj = { foo: 'bar', bar: 'baz', baz: 'qux' }; ``` -------------------------------- ### Joomla! SCSS Property Prefixing Source: https://developer.joomla.org/coding-standards/scss States that vendor prefixes for CSS properties are not required in the source SCSS files. The build process automatically handles the addition of necessary prefixes. ```CSS // Good .example { transform: rotate(30px); } // Bad - uses prefix .example { -webkit-transform: rotate(30px); transform: rotate(30px); } ```