From 3c2bd7c444684f7a9eacf81202df5e66beaaddb7 Mon Sep 17 00:00:00 2001 From: pb30 Date: Mon, 18 Nov 2024 16:32:17 -0600 Subject: [PATCH 1/2] Upgrade to composer-dependency-analyser 1.8.1, add `disableExtensionsAnalysis` option --- README.md | 1 + composer.json | 4 ++-- composer.lock | 42 +++++++++++++++++++-------------------- extension.neon | 2 ++ src/ComposerCollector.php | 12 +++++++++-- 5 files changed, 36 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 534d3f8..b84bff5 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ parameters: ignoreAllDevDepsInProd: false ignoreAllProdDepsInDev: false ignoreAllUnusedDeps: false + disableExtensionsAnalysis: false ignoreSpecificUnusedDeps: - laravel/tinker ``` diff --git a/composer.json b/composer.json index 04211ba..6b98b36 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "keywords": ["dev", "static analysis"], "require": { "php": "~8.1|~8.2|~8.3", - "phpstan/phpstan": "^1.12", - "shipmonk/composer-dependency-analyser": "1.7.0" + "phpstan/phpstan": "^1.12.0", + "shipmonk/composer-dependency-analyser": "1.8.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 30b4f3a..a066798 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3247cc1b3a4a4750d40392f0e7f2c7a7", + "content-hash": "d2295caf079bff582911da305eedd2a8", "packages": [ { "name": "phpstan/phpstan", - "version": "1.12.8", + "version": "1.12.11", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c" + "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f6a60a4d66142b8156c9da923f1972657bc4748c", - "reference": "f6a60a4d66142b8156c9da923f1972657bc4748c", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", + "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", "shasum": "" }, "require": { @@ -62,20 +62,20 @@ "type": "github" } ], - "time": "2024-11-06T19:06:49+00:00" + "time": "2024-11-17T14:08:01+00:00" }, { "name": "shipmonk/composer-dependency-analyser", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/shipmonk-rnd/composer-dependency-analyser.git", - "reference": "bca862b2830a453734aee048eb0cdab82e5c9da3" + "reference": "0acd9d94be4d9397055ff012d0abf2ae88072e99" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/shipmonk-rnd/composer-dependency-analyser/zipball/bca862b2830a453734aee048eb0cdab82e5c9da3", - "reference": "bca862b2830a453734aee048eb0cdab82e5c9da3", + "url": "https://api.github.com/repos/shipmonk-rnd/composer-dependency-analyser/zipball/0acd9d94be4d9397055ff012d0abf2ae88072e99", + "reference": "0acd9d94be4d9397055ff012d0abf2ae88072e99", "shasum": "" }, "require": { @@ -84,17 +84,17 @@ "php": "^7.2 || ^8.0" }, "require-dev": { - "editorconfig-checker/editorconfig-checker": "^10.3.0", - "ergebnis/composer-normalize": "^2.19", + "editorconfig-checker/editorconfig-checker": "^10.6.0", + "ergebnis/composer-normalize": "^2.19.0", "ext-dom": "*", "ext-libxml": "*", - "phpcompatibility/php-compatibility": "^9.3", - "phpstan/phpstan": "^1.10.63", - "phpstan/phpstan-phpunit": "^1.1.1", - "phpstan/phpstan-strict-rules": "^1.2.3", - "phpunit/phpunit": "^8.5.28 || ^9.5.20", - "shipmonk/name-collision-detector": "^2.0.0", - "slevomat/coding-standard": "^8.0.1" + "phpcompatibility/php-compatibility": "^9.3.5", + "phpstan/phpstan": "^1.12.3", + "phpstan/phpstan-phpunit": "^1.4.0", + "phpstan/phpstan-strict-rules": "^1.6.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "shipmonk/name-collision-detector": "^2.1.1", + "slevomat/coding-standard": "^8.15.0" }, "bin": [ "bin/composer-dependency-analyser" @@ -126,9 +126,9 @@ ], "support": { "issues": "https://github.com/shipmonk-rnd/composer-dependency-analyser/issues", - "source": "https://github.com/shipmonk-rnd/composer-dependency-analyser/tree/1.7.0" + "source": "https://github.com/shipmonk-rnd/composer-dependency-analyser/tree/1.8.1" }, - "time": "2024-08-08T08:12:32+00:00" + "time": "2024-11-18T12:58:21+00:00" } ], "packages-dev": [ diff --git a/extension.neon b/extension.neon index ea93001..0c46ce2 100644 --- a/extension.neon +++ b/extension.neon @@ -18,6 +18,7 @@ parameters: ignoreAllDevDepsInProd: false ignoreAllProdDepsInDev: false ignoreAllUnusedDeps: false + disableExtensionsAnalysis: false ignoreSpecificUnusedDeps: [] parametersSchema: @@ -28,5 +29,6 @@ parametersSchema: ignoreAllDevDepsInProd: bool() ignoreAllProdDepsInDev: bool() ignoreAllUnusedDeps: bool() + disableExtensionsAnalysis: bool() ignoreSpecificUnusedDeps: listOf(string()) ]) diff --git a/src/ComposerCollector.php b/src/ComposerCollector.php index d753e7c..b5cad4a 100644 --- a/src/ComposerCollector.php +++ b/src/ComposerCollector.php @@ -37,6 +37,8 @@ class ComposerCollector implements Collector private bool $ignoreAllUnusedDeps = false; + private bool $disableExtensionsAnalysis = false; + /** @var string[] */ private array $ignoreSpecificUnusedDeps = []; @@ -54,6 +56,7 @@ public function __construct(string $cwd, array $options) $this->ignoreAllDevDepsInProd = boolval($options['ignoreAllDevDepsInProd'] ?? false); $this->ignoreAllProdDepsInDev = boolval($options['ignoreAllProdDepsInDev'] ?? false); $this->ignoreAllUnusedDeps = boolval($options['ignoreAllUnusedDeps'] ?? false); + $this->disableExtensionsAnalysis = boolval($options['disableExtensionsAnalysis'] ?? false); $this->ignoreSpecificUnusedDeps = $options['ignoreSpecificUnusedDeps'] ?? []; $results = $this->runComposerDependencyAnalyser(); @@ -63,8 +66,8 @@ public function __construct(string $cwd, array $options) private function runComposerDependencyAnalyser(): AnalysisResult { // From vendor/shipmonk/composer-dependency-analyser/bin/composer-dependency-analyser - $stdOutPrinter = new Printer(resource: STDOUT); - $stdErrPrinter = new Printer(resource: STDERR); + $stdOutPrinter = new Printer(resource: STDOUT, noColor: true); + $stdErrPrinter = new Printer(resource: STDERR, noColor: true); $initializer = new ComposerInitializer(cwd: $this->cwd, stdOutPrinter: $stdOutPrinter, stdErrPrinter: $stdErrPrinter); $stopwatch = new Stopwatch; $options = $initializer->initCliOptions(cwd: $this->cwd, argv: []); @@ -98,6 +101,11 @@ private function runComposerDependencyAnalyser(): AnalysisResult $configuration->ignoreErrors([ErrorType::UNUSED_DEPENDENCY]); } + if ($this->disableExtensionsAnalysis) { + echo 'disabled'; + $configuration->disableExtensionsAnalysis(); + } + foreach ($this->ignoreSpecificUnusedDeps as $packageName) { $configuration->ignoreErrorsOnPackage($packageName, [ErrorType::UNUSED_DEPENDENCY]); } From 36e03e1fc08f51fb483aaaa293069cac9383b696 Mon Sep 17 00:00:00 2001 From: pb30 Date: Wed, 13 Nov 2024 15:26:31 -0600 Subject: [PATCH 2/2] Fix types --- src/ComposerRule.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ComposerRule.php b/src/ComposerRule.php index 8aacb46..3e918a9 100644 --- a/src/ComposerRule.php +++ b/src/ComposerRule.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Node\CollectedDataNode; use PHPStan\Rules\Rule; +use PHPStan\Rules\RuleError; class ComposerRule implements Rule { @@ -21,6 +22,9 @@ public function getNodeType(): string return CollectedDataNode::class; } + /** + * @return RuleError[] + */ public function processNode(Node $node, Scope $scope): array { $errors = $this->depAnalyzer::$results;