Skip to content

Commit 6c4477c

Browse files
committed
PHPStanDiagnoseExtension - skip showing config files in "Included configs from Composer packages" if already present in the "Extension installer" section
1 parent 58d202f commit 6c4477c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

phpstan-baseline.neon

+15
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ parameters:
159159
count: 1
160160
path: src/DependencyInjection/NeonAdapter.php
161161

162+
-
163+
message: "#^Creating new ReflectionClass is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine\\. Use objects retrieved from ReflectionProvider instead\\.$#"
164+
count: 1
165+
path: src/Diagnose/PHPStanDiagnoseExtension.php
166+
167+
-
168+
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig\\>\\|PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig, string given\\.$#"
169+
count: 1
170+
path: src/Diagnose/PHPStanDiagnoseExtension.php
171+
172+
-
173+
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#"
174+
count: 1
175+
path: src/Diagnose/PHPStanDiagnoseExtension.php
176+
162177
-
163178
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
164179
count: 1

src/Diagnose/PHPStanDiagnoseExtension.php

+25
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
use PHPStan\File\FileHelper;
99
use PHPStan\Internal\ComposerHelper;
1010
use PHPStan\Php\PhpVersion;
11+
use ReflectionClass;
1112
use function array_key_exists;
1213
use function array_slice;
1314
use function class_exists;
1415
use function count;
1516
use function dirname;
1617
use function explode;
1718
use function implode;
19+
use function in_array;
1820
use function is_file;
21+
use function is_readable;
1922
use function sprintf;
2023
use function str_starts_with;
2124
use function strlen;
@@ -69,13 +72,32 @@ public function print(Output $output): void
6972
}
7073
$output->writeLineFormatted('');
7174

75+
$configFilesFromExtensionInstaller = [];
7276
if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) {
7377
$output->writeLineFormatted('<info>Extension installer:</info>');
7478
if (count(GeneratedConfig::EXTENSIONS) === 0) {
7579
$output->writeLineFormatted('No extensions installed');
7680
}
81+
82+
$generatedConfigReflection = new ReflectionClass('PHPStan\ExtensionInstaller\GeneratedConfig');
83+
$generatedConfigDirectory = dirname($generatedConfigReflection->getFileName());
7784
foreach (GeneratedConfig::EXTENSIONS as $name => $extensionConfig) {
7885
$output->writeLineFormatted(sprintf('%s: %s', $name, $extensionConfig['version'] ?? 'Unknown version'));
86+
foreach ($extensionConfig['extra']['includes'] ?? [] as $includedFile) {
87+
$includedFilePath = null;
88+
if (isset($extensionConfig['relative_install_path'])) {
89+
$includedFilePath = sprintf('%s/%s/%s', $generatedConfigDirectory, $extensionConfig['relative_install_path'], $includedFile);
90+
if (!is_file($includedFilePath) || !is_readable($includedFilePath)) {
91+
$includedFilePath = null;
92+
}
93+
}
94+
95+
if ($includedFilePath === null) {
96+
$includedFilePath = sprintf('%s/%s', $extensionConfig['install_path'], $includedFile);
97+
}
98+
99+
$configFilesFromExtensionInstaller[] = $this->fileHelper->normalizePath($includedFilePath, '/');
100+
}
79101
}
80102
} else {
81103
$output->writeLineFormatted('<info>Extension installer:</info> Not installed');
@@ -85,6 +107,9 @@ public function print(Output $output): void
85107
$thirdPartyIncludedConfigs = [];
86108
foreach ($this->allConfigFiles as $configFile) {
87109
$configFile = $this->fileHelper->normalizePath($configFile, '/');
110+
if (in_array($configFile, $configFilesFromExtensionInstaller, true)) {
111+
continue;
112+
}
88113
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
89114
$composerConfig = ComposerHelper::getComposerConfig($composerAutoloaderProjectPath);
90115
if ($composerConfig === null) {

0 commit comments

Comments
 (0)