Skip to content

Commit 544855b

Browse files
committed
PHPCSDev ruleset: switch over to PSR12 and other minor tweaks
This switches the basis of the `PHPCSDev` ruleset over to PSR12 with a few, selective exceptions: * Constant visibility will not be demanded as the minimum PHP requirement of PHPCS is PHP 5.4 and constant visibility did not become available until PHP 7.1. * The first condition of a multi-line control structure is allowed to be on the same line as the control structure keyword (PSR2 style). Includes updating the Readme to reflect this change. Includes removing some individual rule includes which are now already included via PSR12. **Note:** PSR12 enforces a blank line between each of the file header blocks. This rule can currently not (yet) be turned off in a modular way, i.e. for just one block. It is either on or off. This rule conflicts with the common practice of having no blank line between the PHP open tag and the file docblock. To turn this rule off, add `<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/>` to the project specific ruleset, like is done in this PR for the PHPCSDevTools native project ruleset.
1 parent d2f355b commit 544855b

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

PHPCSDev/ruleset.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPCSDev" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
33

4-
<description>A PSR-2 based standard for use by sniff developers to check the code style of external PHPCS standards</description>
4+
<description>A PSR-12 based standard for use by sniff developers to check the code style of external PHPCS standards</description>
55

66
<!--
77
####################################################################
@@ -28,10 +28,18 @@
2828

2929
<!--
3030
####################################################################
31-
Code style: Check style for compliance with PSR2.
31+
Code style: Check style for compliance with PSR12.
3232
####################################################################
3333
-->
34-
<rule ref="PSR2"/>
34+
<rule ref="PSR12">
35+
<!-- As PHP 5.4 is the minimum supported PHP version for PHP_CodeSniffer and
36+
most external standards, adding constant visibility is not (yet) an option. -->
37+
<exclude name="PSR12.Properties.ConstantVisibility"/>
38+
39+
<!-- Allow for the first condition of a multi-line control structure to be on the same line
40+
as the control structure keyword. -->
41+
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.FirstExpressionLine"/>
42+
</rule>
3543

3644

3745
<!--
@@ -60,7 +68,7 @@
6068
####################################################################
6169
-->
6270

63-
<!-- PSR2 appears to ignore blank lines for superfluous whitespace and in several other places. Let's fix that. -->
71+
<!-- PSR12 appears to ignore blank lines for superfluous whitespace and in several other places. Let's fix that. -->
6472
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
6573
<properties>
6674
<property name="ignoreBlankLines" value="false"/>
@@ -89,11 +97,7 @@
8997
</properties>
9098
</rule>
9199

92-
<rule ref="Generic.PHP.LowerCaseType"/>
93100
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing"/>
94-
<rule ref="PSR12.Classes.ClassInstantiation"/>
95-
<rule ref="PSR12.Keywords.ShortFormTypeKeywords"/>
96-
<rule ref="PSR12.Operators.OperatorSpacing"/>
97101

98102
<!-- Align the equal operator in assignment blocks. -->
99103
<rule ref="Generic.Formatting.MultipleStatementAlignment">

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Often, sniff repos will use the code style of the standard they are adding. Howe
185185
So for those repos which need a basic standard which will still keep their code-base consistent, this standard should be useful.
186186

187187
The standard checks your code against the following:
188-
* Compliance with [PSR-2](https://www.php-fig.org/psr/psr-2/).
188+
* Compliance with [PSR-12](https://www.php-fig.org/psr/psr-12/), with a few exceptions.
189189
* Use of camelCase variable and function names.
190190
* Use of normalized arrays.
191191
* All files, classes, functions and properties are documented with a docblock and contain the minimally needed information.

phpcs.xml.dist

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@
3232
#############################################################################
3333
-->
3434

35-
<rule ref="PHPCSDev"/>
35+
<rule ref="PHPCSDev">
36+
<!-- Allow for the file docblock on the line directly following the PHP open tag.
37+
As the sniff in PHPCS does not use modular error codes (yet - see PR #2729),
38+
the complete error code needs to be disabled, not just the bit involving
39+
the file docblocks.
40+
-->
41+
<exclude name="PSR12.Files.FileHeader.SpacingAfterBlock"/>
42+
</rule>
3643

3744
<!-- Set minimum PHP version supported to PHP 5.4. -->
3845
<config name="testVersion" value="5.4-"/>

0 commit comments

Comments
 (0)