Skip to content

Commit

Permalink
PHPStanDiagnoseExtension - skip showing config files in "Included con…
Browse files Browse the repository at this point in the history
…figs from Composer packages" if already present in the "Extension installer" section
  • Loading branch information
ondrejmirtes committed Aug 19, 2024
1 parent 58d202f commit 6c4477c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ parameters:
count: 1
path: src/DependencyInjection/NeonAdapter.php

-
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\\.$#"
count: 1
path: src/Diagnose/PHPStanDiagnoseExtension.php

-
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig\\>\\|PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig, string given\\.$#"
count: 1
path: src/Diagnose/PHPStanDiagnoseExtension.php

-
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#"
count: 1
path: src/Diagnose/PHPStanDiagnoseExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
count: 1
Expand Down
25 changes: 25 additions & 0 deletions src/Diagnose/PHPStanDiagnoseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
use PHPStan\File\FileHelper;
use PHPStan\Internal\ComposerHelper;
use PHPStan\Php\PhpVersion;
use ReflectionClass;
use function array_key_exists;
use function array_slice;
use function class_exists;
use function count;
use function dirname;
use function explode;
use function implode;
use function in_array;
use function is_file;
use function is_readable;
use function sprintf;
use function str_starts_with;
use function strlen;
Expand Down Expand Up @@ -69,13 +72,32 @@ public function print(Output $output): void
}
$output->writeLineFormatted('');

$configFilesFromExtensionInstaller = [];
if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) {
$output->writeLineFormatted('<info>Extension installer:</info>');
if (count(GeneratedConfig::EXTENSIONS) === 0) {
$output->writeLineFormatted('No extensions installed');
}

$generatedConfigReflection = new ReflectionClass('PHPStan\ExtensionInstaller\GeneratedConfig');
$generatedConfigDirectory = dirname($generatedConfigReflection->getFileName());
foreach (GeneratedConfig::EXTENSIONS as $name => $extensionConfig) {
$output->writeLineFormatted(sprintf('%s: %s', $name, $extensionConfig['version'] ?? 'Unknown version'));
foreach ($extensionConfig['extra']['includes'] ?? [] as $includedFile) {

Check failure on line 86 in src/Diagnose/PHPStanDiagnoseExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Parameter #1 $argument of class ReflectionClass constructor expects class-string<PHPStan\ExtensionInstaller\GeneratedConfig>|PHPStan\ExtensionInstaller\GeneratedConfig, string given.

Check failure on line 86 in src/Diagnose/PHPStanDiagnoseExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Parameter #1 $argument of class ReflectionClass constructor expects class-string<PHPStan\ExtensionInstaller\GeneratedConfig>|PHPStan\ExtensionInstaller\GeneratedConfig, string given.
$includedFilePath = null;
if (isset($extensionConfig['relative_install_path'])) {
$includedFilePath = sprintf('%s/%s/%s', $generatedConfigDirectory, $extensionConfig['relative_install_path'], $includedFile);
if (!is_file($includedFilePath) || !is_readable($includedFilePath)) {

Check failure on line 90 in src/Diagnose/PHPStanDiagnoseExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Parameter #1 $argument of class ReflectionClass constructor expects class-string<PHPStan\ExtensionInstaller\GeneratedConfig>|PHPStan\ExtensionInstaller\GeneratedConfig, string given.

Check failure on line 90 in src/Diagnose/PHPStanDiagnoseExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Parameter #1 $argument of class ReflectionClass constructor expects class-string<PHPStan\ExtensionInstaller\GeneratedConfig>|PHPStan\ExtensionInstaller\GeneratedConfig, string given.
$includedFilePath = null;
}
}

if ($includedFilePath === null) {
$includedFilePath = sprintf('%s/%s', $extensionConfig['install_path'], $includedFile);

Check failure on line 96 in src/Diagnose/PHPStanDiagnoseExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Parameter #1 $argument of class ReflectionClass constructor expects class-string<PHPStan\ExtensionInstaller\GeneratedConfig>|PHPStan\ExtensionInstaller\GeneratedConfig, string given.

Check failure on line 96 in src/Diagnose/PHPStanDiagnoseExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Parameter #1 $argument of class ReflectionClass constructor expects class-string<PHPStan\ExtensionInstaller\GeneratedConfig>|PHPStan\ExtensionInstaller\GeneratedConfig, string given.
}

$configFilesFromExtensionInstaller[] = $this->fileHelper->normalizePath($includedFilePath, '/');
}
}
} else {
$output->writeLineFormatted('<info>Extension installer:</info> Not installed');
Expand All @@ -85,6 +107,9 @@ public function print(Output $output): void
$thirdPartyIncludedConfigs = [];
foreach ($this->allConfigFiles as $configFile) {
$configFile = $this->fileHelper->normalizePath($configFile, '/');
if (in_array($configFile, $configFilesFromExtensionInstaller, true)) {
continue;
}
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
$composerConfig = ComposerHelper::getComposerConfig($composerAutoloaderProjectPath);
if ($composerConfig === null) {
Expand Down

0 comments on commit 6c4477c

Please sign in to comment.