Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Analyser/FileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ public function analyseFile(
$this->collectErrors($analysedFiles);
$parserNodes = $this->parser->parseFile($file);
$linesToIgnore = $unmatchedLineIgnores = [$file => $this->getLinesToIgnoreFromTokens($parserNodes)];
$ignoreErrorExtensions = $this->ignoreErrorExtensionProvider->getExtensions();
$temporaryFileErrors = [];
$nodeCallback = function (Node $node, $scope, int $callbackInvocationNumber) use (&$fileErrors, &$fileCollectedData, &$fileDependencies, &$usedTraitFileDependencies, &$exportedNodes, $file, $ruleRegistry, $collectorRegistry, $outerNodeCallback, $analysedFiles, &$linesToIgnore, &$unmatchedLineIgnores, &$temporaryFileErrors, $parserNodes): void {
$nodeCallback = function (Node $node, $scope, int $callbackInvocationNumber) use (&$fileErrors, &$fileCollectedData, &$fileDependencies, &$usedTraitFileDependencies, &$exportedNodes, $file, $ruleRegistry, $collectorRegistry, $outerNodeCallback, $analysedFiles, &$linesToIgnore, &$unmatchedLineIgnores, &$temporaryFileErrors, $parserNodes, $ignoreErrorExtensions): void {
/** @var Scope&NodeCallbackInvoker $scope */
if ($node instanceof Node\Stmt\Trait_) {
foreach (array_keys($linesToIgnore[$file] ?? []) as $lineToIgnore) {
Expand Down Expand Up @@ -171,7 +172,7 @@ public function analyseFile(
$error = $this->ruleErrorTransformer->transform($ruleError, $scope, $parserNodes, $node);

if ($error->canBeIgnored()) {
foreach ($this->ignoreErrorExtensionProvider->getExtensions() as $ignoreErrorExtension) {
Copy link
Contributor Author

@staabm staabm Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method was invoked once for every error found

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make sense to move it completely out of the callback and just use its variable? Maybe measure the memory difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see a measurable improvement, even though this loop callback is invoked 800.000 times

foreach ($ignoreErrorExtensions as $ignoreErrorExtension) {
if ($ignoreErrorExtension->shouldIgnore($error, $node, $scope)) {
continue 2;
}
Expand Down
Loading