View Issue Details

IDProjectCategoryView StatusLast Update
0003681Composrcorepublic2019-12-03 18:52
ReporterSalmanAssigned ToChris Graham 
Status resolvedResolutionfixed 
Product Version 
Fixed in Version 
Summary0003681: Run the PHP codebase through PHP_CodeSniffer beautifier
DescriptionRunning the beautifier breaks easy merging so we need to take that into consideration. Sometimes reformatted spacing can make code harder to follow but we can fine tune the Code Sniffer config file to deal with that I think.

Attached is the rule set config file following coding standards agreed at

PHPStorm can be configured to use the rule set or a report can be generated by installing Code Sniffer using Composer `composer global require "squizlabs/php_codesniffer=*"` and running `phpcs --standard=phpcs.xml --parallel=1024`.

Beautifier is `phpcbf --standard=phpcs.xml --parallel=1024`.
TagsRoadmap: v11, Type: Standards compliance
Attach Tags
Time estimation (hours)7
Sponsorship open


related to 0002747 non-assigned PHP refresh (ongoing) 
related to 0003860 resolvedChris Graham Use PSR-12 standard 



2018-09-07 18:21


phpcs.xml.txt (3,047 bytes)
<?xml version="1.0"?>
<!-- PHP_CodeSniffer ruleset file -->
<!-- Example: -->
<ruleset name="PHP_CodeSniffer">
	<description>PHP coding standard for Composr CMS</description>


	<!-- Exclude third-party code -->
	<!-- Include the PSR2 standard ( -->
	<!-- We only partially follow it: -->
	<rule ref="PSR2">
		<!-- Excludes with the generated error messages mentioned: -->
		<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
		<!-- ^ "Method name [...] is not in camel caps format" -->
		<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
		<!-- ^ "Each class must be in a namespace of at least one level (a top-level vendor name)" -->
		<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
		<!-- ^ "Method name should not be prefixed with an underscore to indicate visibility" -->
		<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
		<!-- ^ "Property name [...] should not be prefixed with an underscore to indicate visibility" -->
		<exclude name="Generic.Files.LineLength.TooLong" />
		<!-- ^ "Line exceeds 120 characters" -->
		<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
		<!-- ^ "Class name [...] is not in PascalCase format" -->
		<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
		<!-- ^ "Each class must be in a file by itself" -->
		<exclude name="Generic.NamingConventions.UpperCaseConstantName.ConstantNotUpperCase" />
		<!-- ^ "Constants must be uppercase; expected 'SOME_CONSTANT' but found 'SOME_constant'" -->
		<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace" />
		<!-- ^ "Expected 0 spaces after opening bracket; newline found" -->
phpcs.xml.txt (3,047 bytes)

Chris Graham

2018-09-07 19:34

administrator   ~0005824

I believe the Code Book lists somewhere the lint tools we currently use, so that should be updated.

The 'external_code_considerations' test needs to be updated to make sure exceptions coded for 3rd party libs are consistent with exceptions coded in other configuration files.

Advantages to running the formatter: closer to the code examples in the PSR-2 spec (which apparently our initial PHPStorm-based is not so much); closer to how our JS code is now formatted.

After running the formatter carefully check over the diff to make sure it's not breaking stuff.

We need to make sure the CQC still works. In particular it checks tabbing by comparing opening and closing brace positions.

Chris Graham

2019-12-03 18:52

administrator   ~0006194

Now implemented.

I've approached this more broadly. PHP CodeSniffer and ESLint are now integrated directly into the CQC, which has also been refactored to have cleaner command line options. These tools are considered deeper checks. ESLint is not expected to have 100% passing, but PHP CodeSniffer is.
Both the PHP CodeSniffer and ESLint configurations are in git. PHP CodeSniffer has been given a PSR-12 configuration.

Additional changes have been made to the CQC so most of the PSR-12 checks can be done by the CQC itself. PHP CodeSniffer is more for very detailed text formatting stuff beyond the simple bracing and operator checks that the CQC does.

The codebook_standards document is updated to reflect PHP CodeSniffer and ESLint as official sources for code beautification and formatting guidance, as well as PSR-12.
We no longer reference PHP CS Fixer.

Running PHP CodeSniffer beautification over the codebase (at time of writing, and barring third party code) produces zero changes, as I have manually gone over to make sure it is 100% compliant.

Issue History

Date Modified Username Field Change
2018-09-07 18:21 Salman New Issue
2018-09-07 18:21 Salman File Added: phpcs.xml.txt
2018-09-07 19:34 Chris Graham Note Added: 0005824
2018-09-07 19:35 Chris Graham Time estimation (hours) => 7
2018-09-07 19:35 Chris Graham Sponsorship open 0 =>
2019-06-27 17:37 Chris Graham Tag Attached: Roadmap: v11
2019-08-12 17:22 Chris Graham Relationship added related to 0003860
2019-08-12 17:23 Chris Graham Tag Attached: Type: Standards compliance
2019-08-12 17:23 Chris Graham Relationship added related to 0002747
2019-12-03 18:52 Chris Graham Assigned To => Chris Graham
2019-12-03 18:52 Chris Graham Status non-assigned => resolved
2019-12-03 18:52 Chris Graham Resolution open => fixed
2019-12-03 18:52 Chris Graham Note Added: 0006194