View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0003681||Composr||core||public||2018-09-07 18:21||2019-12-03 18:52|
|Reporter||Salman||Assigned To||Chris Graham|
|Fixed in Version|
|Summary||0003681: Run the PHP codebase through PHP_CodeSniffer beautifier|
|Description||Running 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 https://compo.sr/tracker/view.php?id=1568
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`.
|Tags||Roadmap: v11, Type: Standards compliance|
|Time estimation (hours)||7|
phpcs.xml.txt (3,047 bytes)
<?xml version="1.0"?> <!-- PHP_CodeSniffer ruleset file --> <!-- Example: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist --> <ruleset name="PHP_CodeSniffer"> <description>PHP coding standard for Composr CMS</description> <file>sources</file> <file>sources_custom</file> <!-- Exclude third-party code --> <exclude-pattern>sources/diff.php</exclude-pattern> <exclude-pattern>sources/firephp.php</exclude-pattern> <exclude-pattern>sources/jsmin.php</exclude-pattern> <exclude-pattern>sources/lang_stemmer_EN.php</exclude-pattern> <exclude-pattern>sources_custom/aws</exclude-pattern> <exclude-pattern>sources_custom/Cloudinary</exclude-pattern> <exclude-pattern>sources_custom/composr_mobile_sdk/ios</exclude-pattern> <exclude-pattern>sources_custom/facebook</exclude-pattern> <exclude-pattern>sources_custom/geshi</exclude-pattern> <exclude-pattern>sources_custom/getid3</exclude-pattern> <exclude-pattern>sources_custom/ILess</exclude-pattern> <exclude-pattern>sources_custom/photobucket</exclude-pattern> <exclude-pattern>sources_custom/programe</exclude-pattern> <exclude-pattern>sources_custom/sabredav</exclude-pattern> <exclude-pattern>sources_custom/spout</exclude-pattern> <exclude-pattern>sources_custom/sugar_crm_lib.php</exclude-pattern> <exclude-pattern>sources_custom/swift_mailer</exclude-pattern> <exclude-pattern>sources_custom/Transliterator</exclude-pattern> <exclude-pattern>sources_custom/twitter.php</exclude-pattern> <!-- Include the PSR2 standard (https://www.php-fig.org/psr/psr-2/) --> <!-- We only partially follow it: https://compo.sr/tracker/view.php?id=1568 --> <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" --> </rule> </ruleset>
phpcs.xml.txt (3,047 bytes)
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.
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.
|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|