View Issue Details

IDProjectCategoryView StatusLast Update
0003681Composrcorepublic2019-08-12 17:23
ReporterSalmanAssigned To 
Severityfeature 
Status non-assignedResolutionopen 
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 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`.
TagsRoadmap: v11, Type: Standards compliance
Attach Tags
Time estimation (hours)7
Sponsorship open

Relationships

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

Activities

Salman

2018-09-07 18:21

administrator  

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)

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.

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