Skip to content

Commit

Permalink
CS rules: tweak array rules for test files
Browse files Browse the repository at this point in the history
Test files often use data providers (or should).
Data providers are provided as arrays (as `yield` is not supported in the minimum supported PHP version of PHPCS).

As things were, single item arrays would be forced to be single-line, while multi-item arrays would be forced to be multi-line.

For large data provider arrays which have a mix of single item and multi-item sub-arrays, this decreases the scannability of the test cases.

For that reason, I'm disabling the enforcement of "single item arrays should be single line" for all test files.

In practice this means that multi-item arrays still need to be multi-line, but that single item arrays can be either single line or multi-line, whichever is best for readability of the test data.

Related to 155
  • Loading branch information
jrfnl committed Jan 3, 2024
1 parent da51554 commit 91ae2f4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
<severity>0</severity>
</rule>

<!-- Don't enforce single line arrays for single item arrays in test files. Readability over brevity. -->
<rule ref="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed">
<exclude-pattern>tests/*\.php$</exclude-pattern>
<exclude-pattern>Standards/*/Tests/*/*UnitTest\.php$</exclude-pattern>
</rule>

<!-- Check var names, but we don't want leading underscores for private vars -->
<rule ref="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
Expand Down

0 comments on commit 91ae2f4

Please sign in to comment.