Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup unsupported extensions message #9089

Merged
Merged
69 changes: 68 additions & 1 deletion src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,73 @@ class Config
"xdebug" => false,
];

/**
* A list of php extensions described in CallMap Psalm files
* as opposite to stub files loaded by condition (see stubs/extensions dir).
* @see https://www.php.net/manual/en/extensions.membership.php
*
* @var list<non-empty-string>
* @readonly
*/
public $php_extensions_supported_by_psalm_callmaps = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not a full list, but a good start :)

'apache',
'bcmath',
'bzip2',
'calendar',
'ctype',
'curl',
'dom',
'enchant',
'exif',
'filter',
'gd',
'gettext',
'gmp',
'hash',
'iconv',
'imap',
'intl',
'json',
'ldap',
'libxml',
'mbstring',
'mysqli',
'mysqlnd',
'mhash',
'oci8',
'opcache',
'openssl',
'pcntl',
'PDO',
'pdo_mysql',
'pdo-sqlite',
'pdo-pgsql',
'pgsql',
'pspell',
'phar',
'phpdbg',
'posix',
'redis',
'readline',
'session',
'sockets',
'sqlite3',
'snmp',
'soap',
'sodium',
'shmop',
'sysvsem',
'tidy',
'tokenizer',
'uodbc',
'xml',
'xmlreader',
'xmlwriter',
'xsl',
'zip',
'zlib',
];

/**
* A list of php extensions required by the project that aren't fully supported by Psalm.
*
Expand Down Expand Up @@ -2158,7 +2225,7 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
$this->internal_stubs[] = $ext_stub_path;
$progress->write("Deprecation: Psalm stubs for ext-$ext_name loaded using legacy way."
. " Instead, please declare ext-$ext_name as dependency in composer.json"
. " or use <enableExtensions> directive in Psalm config.\n");
. " or use <enableExtensions> and/or <disableExtensions> directives in Psalm config.\n");
}
}

Expand Down
27 changes: 22 additions & 5 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
use function pcntl_fork;
use function preg_match;
use function rename;
use function sprintf;
use function stream_set_blocking;
use function stream_socket_accept;
use function stream_socket_client;
Expand Down Expand Up @@ -533,8 +534,6 @@ private function generatePHPVersionMessage(): string
{
$codebase = $this->codebase;

$version = $codebase->getMajorAnalysisPhpVersion() . '.' . $codebase->getMinorAnalysisPhpVersion();

switch ($codebase->php_version_source) {
case 'cli':
$source = '(set by CLI argument)';
Expand All @@ -553,9 +552,27 @@ private function generatePHPVersionMessage(): string
break;
}

return "Target PHP version: $version $source Extensions enabled: "
. implode(", ", array_keys(array_filter($codebase->config->php_extensions))) . " (unsupported extensions: "
. implode(", ", array_keys($codebase->config->php_extensions_not_supported)) . ")\n";
$unsupported_php_extensions = array_diff(
array_keys($codebase->config->php_extensions_not_supported),
$codebase->config->php_extensions_supported_by_psalm_callmaps,
);

$message = sprintf(
"Target PHP version: %d.%d %s",
$codebase->getMajorAnalysisPhpVersion(),
$codebase->getMinorAnalysisPhpVersion(),
$source
);

if (count($codebase->config->php_extensions) > 0) {
$message .= ' Enabled extensions: ' . implode(', ', array_keys(array_filter($codebase->config->php_extensions)));
}

if (count($unsupported_php_extensions) > 0) {
$message .= ' (unsupported extensions: ' . implode(', ', $unsupported_php_extensions) . ')';
}

return "$message.\n";
}

public function check(string $base_dir, bool $is_diff = false): void
Expand Down