Skip to content

Commit cce11ae

Browse files
committed
Core: forbid assignments in conditions
As per the proposal in https://make.wordpress.org/core/2019/03/26/coding-standards-updates-for-php-5-6/ Open actions: * [x] Adjust Core PHP handbook to mention this rule in the `Clever code` section
1 parent ca3d41f commit cce11ae

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

WordPress-Core/ruleset.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,13 @@
392392
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
393393
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
394394

395+
<!-- Rule: Assignments must not be placed in placed in conditionals.
396+
Note: sniff is a duplicate of upstream. Can be removed once minimum PHPCS requirement has gone up.
397+
https://github.com/squizlabs/PHP_CodeSniffer/pull/1594
398+
Update: the "assignment in ternary" part of the sniff is currently not yet covered in
399+
the upstream version. This needs to be pulled first before we can defer to upstream. -->
400+
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition"/>
401+
395402
<!-- Rule: In a switch statement... If a case contains a block, then falls through
396403
to the next block, this must be explicitly commented. -->
397404
<!-- Covered by the PSR2.ControlStructures.SwitchDeclaration sniff. -->

WordPress-Extra/ruleset.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
</properties>
2525
</rule>
2626

27-
<!-- Duplicate of upstream. Can be removed once minimum PHPCS requirement has gone up.
28-
https://github.com/squizlabs/PHP_CodeSniffer/pull/1594
29-
Note: the "assignment in ternary" part of the sniff is currently not yet covered in
30-
the upstream version. This needs to be pulled first before we can defer to upstream. -->
31-
<rule ref="WordPress.CodeAnalysis.AssignmentInCondition"/>
32-
3327
<!-- More generic PHP best practices.
3428
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/607 -->
3529
<rule ref="Squiz.PHP.NonExecutableCode"/>

0 commit comments

Comments
 (0)