forked from WordPress/WordPress-Coding-Standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentInTernaryConditionStandard.xml
More file actions
25 lines (24 loc) · 983 Bytes
/
AssignmentInTernaryConditionStandard.xml
File metadata and controls
25 lines (24 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version="1.0"?>
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
title="Assignment In Ternary Condition"
>
<standard>
<![CDATA[
Variables should not be assigned in the condition of a ternary expression. This is likely a mistake, as more often than not, a comparison was intended.
Side-note: This sniff can only detect assignments in ternary conditions when parentheses are used around either the ternary expression or its condition.
]]>
</standard>
<code_comparison>
<code title="Valid: Comparison operator used in ternary condition.">
<![CDATA[
echo ( $a <em>===</em> 'a' ) ? 'b' : 'c';
]]>
</code>
<code title="Invalid: Assignment in ternary condition.">
<![CDATA[
echo ( $a <em>=</em> 'a' ) ? 'b' : 'c';
]]>
</code>
</code_comparison>
</documentation>