Skip to content

Commit

Permalink
Increase PHPStan rule level to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 17, 2024
1 parent 0a1ec0a commit 699c44a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 60 deletions.
48 changes: 1 addition & 47 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,52 +1,6 @@
parameters:
level: 9
level: 10
paths:
- src
- tests/unit
- tests/integration

ignoreErrors:
-
message: "#^Parameter \\#1 \\$items of class SebastianBergmann\\\\Complexity\\\\ComplexityCollection constructor expects array\\<int, SebastianBergmann\\\\Complexity\\\\Complexity\\>, array\\<int\\|string, SebastianBergmann\\\\Complexity\\\\Complexity\\> given\\.$#"
count: 1
path: src/Complexity/ComplexityCollection.php

-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\Complexity\\\\CyclomaticComplexityCalculatingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
count: 1
path: src/Visitor/CyclomaticComplexityCalculatingVisitor.php

-
message: "#^Return type \\(void\\) of method SebastianBergmann\\\\Complexity\\\\CyclomaticComplexityCalculatingVisitor\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
count: 1
path: src/Visitor/CyclomaticComplexityCalculatingVisitor.php

-
message: "#^Return type \\(void\\) of method class@anonymous/tests/unit/ComplexityCalculatingVisitorTest\\.php\\:106\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
count: 1
path: tests/unit/ComplexityCalculatingVisitorTest.php

-
message: "#^Return type \\(void\\) of method class@anonymous/tests/unit/ComplexityCalculatingVisitorTest\\.php\\:106\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
count: 1
path: tests/unit/ComplexityCalculatingVisitorTest.php

-
message: "#^Return type \\(void\\) of method class@anonymous/tests/unit/ComplexityCalculatingVisitorTest\\.php\\:153\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
count: 1
path: tests/unit/ComplexityCalculatingVisitorTest.php

-
message: "#^Return type \\(void\\) of method class@anonymous/tests/unit/ComplexityCalculatingVisitorTest\\.php\\:153\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
count: 1
path: tests/unit/ComplexityCalculatingVisitorTest.php

-
message: "#^Return type \\(void\\) of method class@anonymous/tests/unit/ComplexityCalculatingVisitorTest\\.php\\:59\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitor\\:\\:enterNode\\(\\)$#"
count: 1
path: tests/unit/ComplexityCalculatingVisitorTest.php

-
message: "#^Return type \\(void\\) of method class@anonymous/tests/unit/ComplexityCalculatingVisitorTest\\.php\\:59\\:\\:enterNode\\(\\) should be compatible with return type \\(array\\<PhpParser\\\\Node\\>\\|int\\|PhpParser\\\\Node\\|null\\) of method PhpParser\\\\NodeVisitorAbstract\\:\\:enterNode\\(\\)$#"
count: 1
path: tests/unit/ComplexityCalculatingVisitorTest.php
2 changes: 1 addition & 1 deletion src/Complexity/ComplexityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public static function fromList(Complexity ...$items): self
{
return new self($items);
return new self(array_values($items));
}

/**
Expand Down
9 changes: 1 addition & 8 deletions src/Visitor/ComplexityCalculatingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use function is_array;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
Expand Down Expand Up @@ -111,7 +110,6 @@ private function classMethodName(ClassMethod $node): string
}

assert(isset($parent->namespacedName));
assert($parent->namespacedName instanceof Name);

return $parent->namespacedName->toString() . '::' . $node->name->toString();
}
Expand All @@ -122,12 +120,7 @@ private function classMethodName(ClassMethod $node): string
private function functionName(Function_ $node): string
{
assert(isset($node->namespacedName));
assert($node->namespacedName instanceof Name);

$functionName = $node->namespacedName->toString();

assert($functionName !== '');

return $functionName;
return $node->namespacedName->toString();
}
}
4 changes: 3 additions & 1 deletion src/Visitor/CyclomaticComplexityCalculatingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class CyclomaticComplexityCalculatingVisitor extends NodeVisitorAbstract
*/
private int $cyclomaticComplexity = 1;

public function enterNode(Node $node): void
public function enterNode(Node $node): null
{
switch ($node::class) {
case BooleanAnd::class:
Expand All @@ -49,6 +49,8 @@ public function enterNode(Node $node): void
case While_::class:
$this->cyclomaticComplexity++;
}

return null;
}

/**
Expand Down
12 changes: 9 additions & 3 deletions tests/unit/ComplexityCalculatingVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public function testCalculatesComplexityForAbstractSyntaxTreeOfClass(bool $short
{
private int $numberOfNodesVisited = 0;

public function enterNode(Node $node): void
public function enterNode(Node $node): null
{
$this->numberOfNodesVisited++;

return null;
}

public function numberOfNodesVisited(): int
Expand Down Expand Up @@ -107,9 +109,11 @@ public function testCalculatesComplexityForAbstractSyntaxTreeOfAnonymousClass(bo
{
private int $numberOfNodesVisited = 0;

public function enterNode(Node $node): void
public function enterNode(Node $node): null
{
$this->numberOfNodesVisited++;

return null;
}

public function numberOfNodesVisited(): int
Expand Down Expand Up @@ -154,9 +158,11 @@ public function testCalculatesComplexityForAbstractSyntaxTreeOfInterface(bool $s
{
private int $numberOfNodesVisited = 0;

public function enterNode(Node $node): void
public function enterNode(Node $node): null
{
$this->numberOfNodesVisited++;

return null;
}

public function numberOfNodesVisited(): int
Expand Down

0 comments on commit 699c44a

Please sign in to comment.