• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 12 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Joomla Coding Standards Definition

Joomla Coding Standards Build Status

Latest Stable Version Latest Unstable Version License

This repository includes the Joomla coding standard definition for PHP Codesniffer along with a few other helpful resources. The PHP_CodeSniffer standard will never be 100% accurate, but should be viewed as a strong set of guidelines while writing software for Joomla.

See Joomla coding standards documentation at https://developer.joomla.org/coding-standards.html

If you want to contribute and improve this documentation, you can find the source files in the manual section of the master branch https://github.com/joomla/coding-standards/tree/master/manual

Requirements

Important note: currently the latest PHPCS is the 3.x series. There is a development branch for the Joomla custom sniffs Which is compatible with the PHPCS 3.x series. Although PEAR and composer give you the option to install PHPCS 3.x by default the Joomla custom sniffs releases are currently only compatible with PHPCS 2.x and will not work, so we remind you to always install the PHPCS 2.x series if you are using the Joomla custom sniffs. If you want to test the Joomla Code Standard development branch for PHPCS 3.x, please manually install the 3.x branch.

Installation via Composer

Add "joomla/coding-standards": "~2.0" to the require-dev block in your composer.json and then run composer install.

{
    "require-dev": {
		"joomla/coding-standards": "~2.0"
	}
}

Alternatively, you can simply run the following from the command line:

composer global require squizlabs/php_codesniffer "~2.8"
composer require joomla/coding-standards "~2.0"

As stability of joomla/coding-standards 2.0.0 is currently alpha, make sure you allow usage of alpha software in Composer: In Composer json

{
    "require-dev": {
		"joomla/coding-standards": "~2.0@alpha"
	}
}

or on the command line

composer config minimum-stability "alpha"

If you want to install the coding-standards globally, edit your Composer global configuration by running:

composer global config -e

and add the following: "minimum-stability": "alpha"

Once you have the coding standard files you can tell PHPCS where the standard folder is (i.e. install them in PHPCS)

phpcs --config-set installed_paths /path/to/joomla-coding-standards

Note: the composer scripts will run when the standard is installed globally, but not when it's a dependency. As such, you may want to run PHPCS config-set. When you run PHPCS config-set it will always overwrite the previous values. Use --config-show to check previous values before using --config-set So instead of overwriting the existing paths you should copy the existing paths revealed with --config-show and add each one separated by a comma: phpcs --config-set installed_paths [path_1],[path_2],[/path/to/joomla-coding-standards]

Running

You can use the installed Joomla standard like:

phpcs --standard=Joomla path/to/code

Alternatively if it isn't installed you can still reference it by path like:

phpcs --standard=path/to/joomla/coding-standards path/to/code

Selectively Applying Rules

For consuming packages there are some items that will typically result in creating their own project ruleset.xml, rather than just directly using the Joomla ruleset.xml. A project ruleset.xml allows the coding standard to be selectively applied for excluding 3rd party libraries, for consideration of backwards compatibility in existing projects, or for adjustments necessary for projects that do not need PHP 5.3 compatibility (which will be removed in a future version of the Joomla Coding Standard in connection of the end of PHP 5.3 support in all active Joomla Projects).

For information on selectively applying rules read details in the PHP CodeSniffer wiki

Common Rule Set Adjustments

The most common adjustment is to exclude folders with 3rd party libraries, or where the code has yet to have coding standards applied.

 <!-- Exclude folders not containing production code -->
 <exclude-pattern type="relative">build/*</exclude-pattern>
 <exclude-pattern type="relative">tests/*</exclude-pattern>

 <!-- Exclude 3rd party libraries. -->
 <exclude-pattern type="relative">libraries/*</exclude-pattern>
 <exclude-pattern type="relative">vendor/*</exclude-pattern>

Another common adjustment is to exclude the camelCase format requirement for "Classes, Functions, Methods, Regular Variables and Class Properties" the essentially allows for B/C with snake_case variables which were only allowed in the context of interacting with the database.

 <rule ref="Joomla">
  <exclude name="Joomla.NamingConventions.ValidFunctionName.ScopeNotCamelCaps"/>
  <exclude name="Joomla.NamingConventions.ValidVariableName.NotCamelCaps"/>
  <exclude name="Joomla.NamingConventions.ValidVariableName.MemberNotCamelCaps"/>
  <exclude name="Joomla.NamingConventions.ValidFunctionName.FunctionNoCapital"/>
 </rule>

Old Protected method names were at one time prefixed with an underscore. These Protected method names with underscores are deprecated in Joomla projects but for B/C reasons are still in the projects. As such, excluding the MethodUnderscore sniff is a common ruleset adjustment

 <rule ref="Joomla">
  <exclude name="Joomla.NamingConventions.ValidFunctionName.MethodUnderscore"/>
  <exclude name="Joomla.NamingConventions.ValidVariableName.ClassVarHasUnderscore"/>
 </rule>

The last most common adjustment is removing PHP 5.3 specific rules which prevent short array syntax, and allowing short array syntax for method parameters.

 <rule ref="Generic">
  <exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
 </rule>
 <rule ref="Joomla.Classes.InstantiateNewClasses">
   <properties>
     <property name="shortArraySyntax" value="true"/>
   </properties>
 </rule>
 

Using example rulesets that Selectively Applying Rule

You have to tell you can tell PHPCS where the example ruleset folder is (i.e. install them in PHPCS)

phpcs --config-set installed_paths /path/to/joomla/coding-standards/Example-Rulesets

Note: the composer scripts will run when the standard is installed globally, but not when it's a dependency. As such, you may want to run PHPCS config-set. When you run PHPCS config-set it will always overwrite the previous values. Use --config-show to check previous values before using --config-set So instead of overwriting the existing paths you should copy the existing paths revealed with --config-show and add each one separated by a comma: phpcs --config-set installed_paths [path_1],[path_2],[/path/to/joomla-coding-standards],[/path/to/joomla/coding-standards/Example-Rulesets]

IDE autoformatters

There is further information on how to set up IDE auto formatters here:

https://github.com/joomla/coding-standards/tree/master/Joomla/IDE

More Repositories

1

joomla-cms

Home of the Joomla! Content Management System
PHP
4,650
star
2

joomla-platform

[READ-ONLY] This repo is no longer in active development. Please see https://github.com/joomla/joomla-cms
PHP
542
star
3

joomla-framework

[READ-ONLY] This repo is no longer in active development. Please see https://github.com/joomla-framework for the individual Framework packages.
PHP
189
star
4

jissues

Issue tracking application extending GitHub's issues and pull requests for the Joomla! project.
PHP
71
star
5

Joomla-3.2-Hello-World-Component

PHP
53
star
6

joomla-websites

This repository is for reporting issues with the joomla.org websites only. Please report issues with the Joomla CMS at https://github.com/joomla/joomla-cms/issues/new
45
star
7

framework.joomla.org

Application powering the internet home of the Joomla! Framework
PHP
35
star
8

Manual

Joomla Developer Documentation
JavaScript
23
star
9

volunteers.joomla.org

Extension for the volunteers portal
PHP
21
star
10

joomla-developer-docs

Experimental developer documentation for software produced by the Joomla! project.
JavaScript
20
star
11

joomla-marketing

18
star
12

update.joomla.org

Joomla CMS Update Channel
PHP
16
star
13

downloads.joomla.org

Repository holding custom extensions in use on the Joomla! Downloads Portal
JavaScript
14
star
14

40-backend-template

Joomla 4.0 Backend Template Repository
PHP
14
star
15

joomla-cms-examples

READ ONLY; useful code should be moved to Jdocs
PHP
14
star
16

joomla.org

The Joomla Main Website store
JavaScript
14
star
17

core-translations

PHP
13
star
18

backend-template

backend template for Joomla 4 working area
PHP
13
star
19

rfc

A central place for RFCs for new Features for the Joomla! projects and Specifications (interfaces) for further development.
11
star
20

user-interface-text

A repository for the en-GB style guide of Joomla! language strings.
11
star
21

cross-cms-compliance

Cross-CMS Compliance Coalition
10
star
22

install-from-web-server

Repository holding the component powering the Install from Web server.
PHP
9
star
23

cms-coding-standards

Extended Joomla Coding Standards definition for use in the Joomla CMS environment
9
star
24

help.joomla.org

Application powering the Joomla! Help Screen proxy serving help screens to Joomla! installations
PHP
9
star
25

jed-issues

Joomla! Extensions Directory - Issue Tracker
8
star
26

accessibility

Collaboration to implement accessbility into Joomla
8
star
27

jdoc-examples

This repository contains code examples from the Joomla! Documentation Wiki
7
star
28

cassiopeia

Home of the Cassiopeia frontend template working group for version 4 of the Joomla! Content Management System
PHP
7
star
29

developer.joomla.org

Repository holding custom extensions in use on the Joomla! Developer Network
PHP
7
star
30

schemas

Schemas for the Joomla! CMS
PHP
6
star
31

joomla-surveys

Home of the Surveys Working Group for the Joomla Project.
5
star
32

api.joomla.org

Repository containing the source files for building the Joomla! API website
Twig
5
star
33

community.joomla.org

The Community Website store
PHP
4
star
34

com_jed4

Repository for com_jed4 - Joomla! Extensions Directory
PHP
4
star
35

magazine.joomla.org

The JCM Website store
CSS
3
star
36

Joomla-2.5-Hello-World-Component

PHP
3
star
37

test-system

System testing package for Joomla
PHP
3
star
38

docs.joomla.org

Joomla! Documentation website store
JavaScript
3
star
39

joomlafoundation.org

Repository for the Foundation website
CSS
2
star
40

test-api

Tests for Webservices
Shell
2
star
41

test-javascript

READ ONLY: Javascript testing package for Joomla
JavaScript
2
star
42

test-unit

READ ONLY: Unit Tests for Joomla
PHP
2
star
43

test-integration

Integration testing package for Joomla
PHP
2
star
44

joomla-ux

CSS
2
star
45

forum.joomla.org

The Forum Website store
1
star
46

showcase.joomla.org

The Showcase Website store
CSS
1
star
47

opensourcematters.org

The OSM Website store
CSS
1
star
48

updates

The signed Updates repository for Joomla! core
1
star
49

certification.joomla.org

Certification Website Repository
PHP
1
star
50

3rd-party-extension-testing

Holds the testing code for extension that will be tested with the nighly builds of Joomla!
1
star
51

jed-checker-coding-standards

JED Checker Coding Standards
PHP
1
star
52

tm.joomla.org

The Trademark Website store
CSS
1
star
53

cve-cli-php

The Joomla CVE CLI application written in PHP. This can be used by CNA's to request CVE's from MITRE
1
star