Skip to content

Commit 9508e0d

Browse files
Nic-Sevicjrfnldingo-d
committed
Add: documentation for AssignmentInTernaryCondition sniff
Co-authored-by: Nic <Nic-Sevic@users.noreply.github.com> Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> Co-authored-by: Denis Žoljom <dingo-d@users.noreply.github.com>
1 parent a3f1eed commit 9508e0d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+
title="Assignment In Ternary Condition"
5+
>
6+
<standard>
7+
<![CDATA[
8+
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.
9+
10+
Side-note: This sniff can only detect assignments in ternary conditions when parentheses are used around either the ternary expression or its condition.
11+
]]>
12+
</standard>
13+
<code_comparison>
14+
<code title="Valid: Comparison operator used in ternary condition.">
15+
<![CDATA[
16+
echo ( $a <em>===</em> 'a' ) ? 'b' : 'c';
17+
]]>
18+
</code>
19+
<code title="Invalid: Assignment in ternary condition.">
20+
<![CDATA[
21+
echo ( $a <em>=</em> 'a' ) ? 'b' : 'c';
22+
]]>
23+
</code>
24+
</code_comparison>
25+
</documentation>

0 commit comments

Comments
 (0)