forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ternary operator, null coalescence operator and null coalescence assignment operator to tokens that trigger an increase in cyclomatic complexity
- Loading branch information
MarkBaker
committed
Nov 12, 2021
1 parent
5fb9b64
commit b666b58
Showing
4 changed files
with
271 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 234 additions & 0 deletions
234
src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.2.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
<?php | ||
|
||
function complexityTenWithTernaries() | ||
{ | ||
$value1 = (empty($condition1)) ? $value1A : $value1B; | ||
$value2 = (empty($condition2)) ? $value2A : $value2B; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityElevenWithTernaries() | ||
{ | ||
$value1 = (empty($condition1)) ? $value1A : $value1B; | ||
$value2 = (empty($condition2)) ? $value2A : $value2B; | ||
$value3 = (empty($condition3)) ? $value3A : $value3B; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityTenWithNestedTernaries() | ||
{ | ||
$value1 = true ? $value1A : false ? $value1B : $value1C; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityElevenWithNestedTernaries() | ||
{ | ||
$value1 = (empty($condition1)) ? $value1A : $value1B; | ||
$value2 = true ? $value2A : false ? $value2B : $value2C; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityTenWithNullCoalescence() | ||
{ | ||
$value1 = $value1A ?? $value1B; | ||
$value2 = $value2A ?? $value2B; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityElevenWithNullCoalescence() | ||
{ | ||
$value1 = $value1A ?? $value1B; | ||
$value2 = $value2A ?? $value2B; | ||
$value3 = $value3A ?? $value3B; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityTenWithNestedNullCoalescence() | ||
{ | ||
$value1 = $value1A ?? $value1B ?? $value1C; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityElevenWithNestedNullCoalescence() | ||
{ | ||
$value1 = $value1A ?? $value1B; | ||
$value2 = $value2A ?? $value2B ?? $value2C; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityTenWithNullCoalescenceAssignment() | ||
{ | ||
$value1 ??= $default1; | ||
$value2 ??= $default2; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
function complexityElevenWithNullCoalescenceAssignment() | ||
{ | ||
$value1 ??= $default1; | ||
$value2 ??= $default2; | ||
$value3 ??= $default3; | ||
|
||
switch ($condition) { | ||
case '1': | ||
if ($condition) { | ||
} else if ($cond) { | ||
} | ||
break; | ||
case '2': | ||
while ($cond) { | ||
echo 'hi'; | ||
} | ||
break; | ||
case '3': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.