Skip to content

Commit

Permalink
[Core] Improve performance: remove unnecessary loop StmtsAwareInterfa…
Browse files Browse the repository at this point in the history
…ce to fill Scope on PHPStanNodeScopeResolver (#3048)

* [Core] Improve performance: remove unnecessary loop StmtsAwareInterface to fill Scope on PHPStanNodeScopeResolver

* clean up ignore phpstan complexity for PHPStanNodeScopeResolver

* phpstan ignore cognitive complexity for abstract rector
  • Loading branch information
samsonasik committed Nov 11, 2022
1 parent fced569 commit 21ead88
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
use PHPStan\Type\TypeCombinator;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Caching\FileSystem\DependencyResolver;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\StaticReflection\SourceLocator\ParentAttributeSourceLocator;
use Rector\Core\StaticReflection\SourceLocator\RenamedClassesSourceLocator;
Expand Down Expand Up @@ -166,10 +165,6 @@ public function processNodes(
$node->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}

if ($node instanceof StmtsAwareInterface) {
$this->processStmtsAwareInterface($node, $mutatingScope);
}

if ($node instanceof Trait_) {
$traitName = $this->resolveClassName($node);

Expand Down Expand Up @@ -224,17 +219,6 @@ public function processNodes(
return $this->processNodesWithDependentFiles($filePath, $stmts, $scope, $nodeCallback);
}

private function processStmtsAwareInterface(StmtsAwareInterface $stmtsAware, MutatingScope $mutatingScope): void
{
if ($stmtsAware->stmts === null) {
return;
}

foreach ($stmtsAware->stmts as $stmt) {
$stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
}

private function processArrayItem(ArrayItem $arrayItem, MutatingScope $mutatingScope): void
{
if ($arrayItem->key instanceof Expr) {
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ parameters:
- rules/Php70/EregToPcreTransformer.php
- packages/NodeTypeResolver/NodeTypeResolver.php
- rules/Renaming/NodeManipulator/ClassRenamer.php
- packages/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

- "#^Cognitive complexity for \"Rector\\\\Php70\\\\EregToPcreTransformer\\:\\:(.*?)\" is (.*?), keep it under 10$#"
- '#Cognitive complexity for "Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver\:\:getValue\(\)" is \d+, keep it under 10#'
Expand Down Expand Up @@ -814,3 +813,7 @@ parameters:
-
message: '#"empty\(\$right\)" is forbidden to use#'
path: src/Util/ArrayParametersMerger.php

-
message: '#Cognitive complexity for "Rector\\Core\\Rector\\AbstractRector\:\:enterNode\(\)" is 11, keep it under 10#'
path: src/Rector/AbstractRector.php

0 comments on commit 21ead88

Please sign in to comment.