Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ services:
arguments:
cwd: %currentWorkingDirectory%
options: %composerAnalysis%
tags:
- phpstan.collector

rules:
- ComposerAnalyzer\ComposerRule
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ parameters:
paths:
- src

ignoreErrors:
-
identifier: missingType.generics

composerAnalysis:
ignoreAllShadowDeps: false
ignoreAllDevDepsInProd: false
Expand Down
14 changes: 9 additions & 5 deletions src/ComposerCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
use ShipMonk\ComposerDependencyAnalyser\Result\SymbolUsage;
use ShipMonk\ComposerDependencyAnalyser\Stopwatch;

class ComposerCollector implements Collector
class ComposerCollector
{
/** @var RuleError[] */
public static array $results;

private string $cwd;

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

/**
* @return RuleError[]
*/
public function analyze(): array
{
$results = $this->runComposerDependencyAnalyser();
self::$results = $this->reformatResults($results);

return $this->reformatResults($results);
}

private function runComposerDependencyAnalyser(): AnalysisResult
Expand Down
12 changes: 9 additions & 3 deletions src/ComposerRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;

/**
* @implements Rule<CollectedDataNode>
*/
class ComposerRule implements Rule
{
private ComposerCollector $depAnalyzer;
Expand All @@ -19,6 +22,8 @@ public function __construct(ComposerCollector $depAnalyzer)

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

Expand All @@ -27,9 +32,10 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): array
{
$errors = $this->depAnalyzer::$results;
$this->depAnalyzer::$results = [];
if ($node->isOnlyFilesAnalysis()) {
return [];
}

return $errors;
return $this->depAnalyzer->analyze();
}
}