From da0f04b5432a3adec175f9352a059058a1557533 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 14 Nov 2024 09:02:51 -0300 Subject: [PATCH] Generic/CyclomaticComplexity: improve code coverage --- .../Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php | 2 +- .../Tests/Metrics/CyclomaticComplexityUnitTest.1.inc | 8 +++++++- .../Tests/Metrics/CyclomaticComplexityUnitTest.2.inc | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.2.inc diff --git a/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php b/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php index 8cba81daf2..c37140a990 100644 --- a/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php +++ b/src/Standards/Generic/Sniffs/Metrics/CyclomaticComplexitySniff.php @@ -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; } diff --git a/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.1.inc b/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.1.inc index 494dcc7694..e43b2cdd2a 100644 --- a/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.1.inc +++ b/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.1.inc @@ -451,4 +451,10 @@ function complexityElevenWithNullSafeOperator() $bits = $object5->getX()?->getY()?->getZ(); } -?> +abstract class AbstractClass { + abstract public function sniffShouldIgnoreAbstractMethods(); +} + +interface MyInterface { + public function sniffShouldIgnoreInterfaceMethods(); +} diff --git a/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.2.inc b/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.2.inc new file mode 100644 index 0000000000..9658af3005 --- /dev/null +++ b/src/Standards/Generic/Tests/Metrics/CyclomaticComplexityUnitTest.2.inc @@ -0,0 +1,7 @@ +