Skip to content

Commit

Permalink
Generic/CyclomaticComplexity: improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoprimo authored and jrfnl committed Dec 2, 2024
1 parent 181e255 commit 2b466f1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

// Ignore abstract methods.
// Ignore abstract and interface methods. Bail early when live coding.
if (isset($tokens[$stackPtr]['scope_opener']) === false) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function complexityEleven()
{
while ($condition === true) {
if ($condition) {
} else if ($cond) {
} elseif ($cond) {
}
}

Expand All @@ -61,11 +61,11 @@ function complexityEleven()
echo 'hi';
}
break;
case '3':
break;
default:
break;
}

foreach ($array as $element) {}
}


Expand Down Expand Up @@ -136,14 +136,6 @@ function complexityTwentyOne()
echo 'hi';
}
break;
case '3':
switch ($cond) {
case '1':
break;
case '2':
break;
}
break;
case '4':
do {
if ($condition) {
Expand All @@ -159,8 +151,16 @@ function complexityTwentyOne()
}
break;
}
}

try {
for ($i = 0; $i < 10; $i++) {
if ($i % 2) {
doSomething();
}
}
} catch (Exception $e) {
}
}

function complexityTenWithTernaries()
{
Expand Down Expand Up @@ -451,4 +451,10 @@ function complexityElevenWithNullSafeOperator()
$bits = $object5->getX()?->getY()?->getZ();
}

?>
abstract class AbstractClass {
abstract public function sniffShouldIgnoreAbstractMethods();
}

interface MyInterface {
public function sniffShouldIgnoreInterfaceMethods();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (missing opening curly bracket).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

function sniffShouldBailMissingScopeOpener()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (missing closing curly bracket).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

function sniffShouldBailMissingScopeCloser() {

0 comments on commit 2b466f1

Please sign in to comment.