Skip to content

Commit 01d23a6

Browse files
committed
Core/Extra: tweak the inclusion of the Modernize.FunctionCalls.Dirname sniff
Follow up on 2137 As WP Core has now dropped support for PHP < 7.0, it can start using the `dirname()` `$levels` parameters. Think: ```php // PHP < 7.0. $path = dirname( dirname( dirname( __DIR__ ) ) ); // PHP 7.0+. $path = dirname( __DIR__, 3 ); ``` The `Modernize.FunctionCalls.Dirname` sniff we include also includes a check (and fixer) for that, so we can now include that sniff completely in the `Core` ruleset. For now, I'm proposing to silence the error code related to the PHP 7.0 modernization opportunity (again) for the `Extra` ruleset as not all plugins/themes will have dropped support for PHP < 7.0 yet. To be on the safe side, I'm explicitly excluding the whole sniff from the ruleset used for WPCS itself as WPCS still has a PHP 5.4 minimum.
1 parent 2c593e4 commit 01d23a6

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.phpcs.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050

5151
<!-- Linting is done in a separate CI job, no need to duplicate it. -->
5252
<exclude name="Generic.PHP.Syntax"/>
53+
54+
<!-- WPCS still has a PHP 5.4 minimum. -->
55+
<exclude name="Modernize.FunctionCalls.Dirname"/>
5356
</rule>
5457

5558
<!-- Check code for cross-version PHP compatibility. -->

WordPress-Core/ruleset.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,9 @@
923923
<!-- Check that class name references use the correct case. -->
924924
<rule ref="WordPress.WP.ClassNameCase"/>
925925

926-
<!-- Check that __DIR__ is favoured over dirname(__FILE__).
926+
<!-- Check that __DIR__ is favoured over dirname(__FILE__)
927+
and that dirname( __DIR__, $levels ) is favoured over nested calls to dirname().
927928
See: https://core.trac.wordpress.org/ticket/48082 -->
928-
<rule ref="Modernize.FunctionCalls.Dirname.FileConstant"/>
929+
<rule ref="Modernize.FunctionCalls.Dirname"/>
929930

930931
</ruleset>

WordPress-Extra/ruleset.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
<rule ref="WordPress-Core"/>
77

8+
<!-- Silence the "no nested dirnames, use $levels" notice, which is included in Core,
9+
as plugin/themes may still support PHP < 7.0. -->
10+
<rule ref="Modernize.FunctionCalls.Dirname.Nested">
11+
<severity>0</severity>
12+
</rule>
13+
814
<!-- Generic PHP best practices.
915
https://github.com/WordPress/WordPress-Coding-Standards/pull/382 -->
1016
<rule ref="Generic.PHP.DeprecatedFunctions"/>

0 commit comments

Comments
 (0)