Skip to content

Commit 38ece97

Browse files
authored
Merge pull request #22 from PHPCSStandards/feature/phpcsdev-switch-to-psr-12
PHPCSDev ruleset: switch over to PSR12 and other minor tweaks
2 parents d2f355b + 544855b commit 38ece97

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)