Skip to content

Commit b9ab323

Browse files
authored
Merge pull request #53 from staabm/once
Run analyzer only once
2 parents 16d716a + 56351b2 commit b9ab323

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

extension.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ services:
44
arguments:
55
cwd: %currentWorkingDirectory%
66
options: %composerAnalysis%
7-
tags:
8-
- phpstan.collector
97

108
rules:
119
- ComposerAnalyzer\ComposerRule

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ parameters:
66
paths:
77
- src
88

9-
ignoreErrors:
10-
-
11-
identifier: missingType.generics
12-
139
composerAnalysis:
1410
ignoreAllShadowDeps: false
1511
ignoreAllDevDepsInProd: false

src/ComposerCollector.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
use ShipMonk\ComposerDependencyAnalyser\Result\SymbolUsage;
1717
use ShipMonk\ComposerDependencyAnalyser\Stopwatch;
1818

19-
class ComposerCollector implements Collector
19+
class ComposerCollector
2020
{
21-
/** @var RuleError[] */
22-
public static array $results;
23-
2421
private string $cwd;
2522

2623
/** @var string[] */
@@ -58,9 +55,16 @@ public function __construct(string $cwd, array $options)
5855
$this->ignoreAllUnusedDeps = boolval($options['ignoreAllUnusedDeps'] ?? false);
5956
$this->disableExtensionsAnalysis = boolval($options['disableExtensionsAnalysis'] ?? false);
6057
$this->ignoreSpecificUnusedDeps = $options['ignoreSpecificUnusedDeps'] ?? [];
58+
}
6159

60+
/**
61+
* @return RuleError[]
62+
*/
63+
public function analyze(): array
64+
{
6265
$results = $this->runComposerDependencyAnalyser();
63-
self::$results = $this->reformatResults($results);
66+
67+
return $this->reformatResults($results);
6468
}
6569

6670
private function runComposerDependencyAnalyser(): AnalysisResult

src/ComposerRule.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use PHPStan\Rules\Rule;
99
use PHPStan\Rules\RuleError;
1010

11+
/**
12+
* @implements Rule<CollectedDataNode>
13+
*/
1114
class ComposerRule implements Rule
1215
{
1316
private ComposerCollector $depAnalyzer;
@@ -19,6 +22,8 @@ public function __construct(ComposerCollector $depAnalyzer)
1922

2023
public function getNodeType(): string
2124
{
25+
// use collector rule, to make sure we run the underlying analyzer only once
26+
// see https://github.com/pb30/phpstan-composer-analysis/issues/10
2227
return CollectedDataNode::class;
2328
}
2429

@@ -27,9 +32,10 @@ public function getNodeType(): string
2732
*/
2833
public function processNode(Node $node, Scope $scope): array
2934
{
30-
$errors = $this->depAnalyzer::$results;
31-
$this->depAnalyzer::$results = [];
35+
if ($node->isOnlyFilesAnalysis()) {
36+
return [];
37+
}
3238

33-
return $errors;
39+
return $this->depAnalyzer->analyze();
3440
}
3541
}

0 commit comments

Comments
 (0)