Skip to content

Commit

Permalink
Do not try to process abstract methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 31, 2023
1 parent 53bca56 commit 4ff9a18
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Visitor/ComplexityCalculatingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function enterNode(Node $node): ?int
return null;
}

if ($node->isAbstract()) {
return null;
}

$name = $this->classMethodName($node);
} else {
$name = $this->functionName($node);
Expand Down
4 changes: 3 additions & 1 deletion tests/_fixture/ExampleClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
namespace SebastianBergmann\Complexity\TestFixture;

final class ExampleClass
abstract class ExampleClass
{
public function method(): void
{
Expand Down Expand Up @@ -43,4 +43,6 @@ public function method(): void
do {
} while (false);
}

abstract public function abstractMethod(): void;
}
4 changes: 2 additions & 2 deletions tests/unit/ComplexityCalculatingVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function numberOfNodesVisited(): int
$this->assertSame(14, $complexityCalculatingVisitor->result()->cyclomaticComplexity());

if ($shortCircuitTraversal) {
$this->assertSame(9, $shortCircuitVisitor->numberOfNodesVisited());
$this->assertSame(12, $shortCircuitVisitor->numberOfNodesVisited());
} else {
$this->assertSame(70, $shortCircuitVisitor->numberOfNodesVisited());
$this->assertSame(73, $shortCircuitVisitor->numberOfNodesVisited());
}
}

Expand Down

0 comments on commit 4ff9a18

Please sign in to comment.