Skip to content

Commit 2880e5b

Browse files
authored
Merge pull request #2133 from WordPress/feature/core-move-object-instantiation-rules
Core: move rules related to object instantiations from Extra to Core
2 parents acbca75 + 47d93c0 commit 2880e5b

File tree

8 files changed

+19
-523
lines changed

8 files changed

+19
-523
lines changed

WordPress-Core/ruleset.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,25 @@
425425
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
426426

427427

428+
<!--
429+
#############################################################################
430+
Handbook: Object-Oriented Programming - Object Instantiation.
431+
Ref: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#object-instantiation
432+
#############################################################################
433+
-->
434+
<!-- Covers rule: When instantiating a new object instance, parenthesis must always be used, even when not strictly necessary. -->
435+
<rule ref="PSR12.Classes.ClassInstantiation"/>
436+
<rule ref="Universal.Classes.RequireAnonClassParentheses"/>
437+
438+
<!-- Covers rule: There should be no space between the name of the class being instantiated and the opening parenthesis. -->
439+
<!-- Covered by the PEAR.Functions.FunctionCallSignature sniff for non-anonymous classes. -->
440+
<rule ref="Universal.WhiteSpace.AnonClassKeywordSpacing">
441+
<properties>
442+
<property name="spacing" value="0"/>
443+
</properties>
444+
</rule>
445+
446+
428447
<!--
429448
#############################################################################
430449
Handbook: Control Structures - Use elseif, not else if.

WordPress-Extra/ruleset.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@
122122
<!-- Validates post type slugs for valid characters, length and reserved keywords. -->
123123
<rule ref="WordPress.NamingConventions.ValidPostTypeSlug"/>
124124

125-
<!-- Check that object instantiations always have braces & are not assigned by reference.
126-
https://github.com/WordPress/WordPress-Coding-Standards/issues/919
127-
Note: there is a similar upstream sniff `PSR12.Classes.ClassInstantiation`, however
128-
that sniff:
129-
- does not cover JS files;
130-
- does not demand parentheses for PHP anonymous classes;
131-
- does not check the whitespace between the class name and the parentheses;
132-
- does not check for PHP new by reference.
133-
For those reasons, the WPCS version should remain. -->
134-
<rule ref="WordPress.Classes.ClassInstantiation"/>
135-
136125
<!-- https://github.com/WordPress/WordPress-Coding-Standards/issues/1157 -->
137126
<rule ref="WordPress.Security.PluginMenuSlug"/>
138127
<rule ref="WordPress.WP.CronInterval"/>

WordPress/Sniffs/Classes/ClassInstantiationSniff.php

Lines changed: 0 additions & 205 deletions
This file was deleted.

WordPress/Tests/Classes/ClassInstantiationUnitTest.inc

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)