From ce8dcdfee7c67db76714a7c7c1d6bc6ad3dcffd7 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Thu, 5 Jan 2023 17:02:35 +0400 Subject: [PATCH 1/4] Do not list core and bundled extensions as unsupported --- src/Psalm/Config.php | 35 ++++++++++++++++++- .../Internal/Analyzer/ProjectAnalyzer.php | 27 +++++++++++--- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 096d6d32c..f67fd075b 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -612,6 +612,39 @@ 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). + * + * @var list + * @readonly + */ + public $php_extensions_supported_by_psalm_callmaps = [ + 'apache', + 'bcmath', + 'calendar', + 'ctype', + 'curl', + 'dom', + 'exif', + 'filter', + 'gd', + 'hash', + 'iconv', + 'intl', + 'json', + 'libxml', + 'mbstring', + 'opcache', + 'openssl', + 'pcntl', + 'PDO', + 'pdo_mysql', + 'redis', + 'tokenizer', + 'zip', + ]; + /** * A list of php extensions required by the project that aren't fully supported by Psalm. * @@ -2151,7 +2184,7 @@ class Config $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 directive in Psalm config.\n"); + . " or use and/or directives in Psalm config.\n"); } } diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index d256db9ff..6211e7ea6 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -85,6 +85,7 @@ use function number_format; 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; @@ -533,8 +534,6 @@ class ProjectAnalyzer { $codebase = $this->codebase; - $version = $codebase->getMajorAnalysisPhpVersion() . '.' . $codebase->getMinorAnalysisPhpVersion(); - switch ($codebase->php_version_source) { case 'cli': $source = '(set by CLI argument)'; @@ -553,9 +552,27 @@ class ProjectAnalyzer 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 From 8b23919241784c91c80ffc386316a8031aac01b8 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Mon, 9 Jan 2023 14:31:17 +0100 Subject: [PATCH 2/4] Extend a list of php ext, supported by CallMap files --- src/Psalm/Config.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index f67fd075b..6aeaa3904 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -615,6 +615,7 @@ class Config /** * 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 * @readonly @@ -622,27 +623,60 @@ class Config public $php_extensions_supported_by_psalm_callmaps = [ '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', ]; /** From 69b6409feb933588a431f2f066578d7662b0c34b Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Tue, 10 Jan 2023 19:24:33 +0100 Subject: [PATCH 3/4] Fix coding-style issues --- src/Psalm/Config.php | 2 +- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index a0b63d9ee..ccbc89cbd 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -615,8 +615,8 @@ class Config /** * 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 * + * @see https://www.php.net/manual/en/extensions.membership.php * @var list * @readonly */ diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 6211e7ea6..3344a763b 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -561,7 +561,7 @@ class ProjectAnalyzer "Target PHP version: %d.%d %s", $codebase->getMajorAnalysisPhpVersion(), $codebase->getMinorAnalysisPhpVersion(), - $source + $source, ); if (count($codebase->config->php_extensions) > 0) { From 3b5d1a485662758b113c07d2c6e0bac6e8a29e31 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Tue, 10 Jan 2023 23:01:40 +0100 Subject: [PATCH 4/4] Fix coding-style issue --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 3344a763b..c89284b29 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -565,7 +565,8 @@ class ProjectAnalyzer ); if (count($codebase->config->php_extensions) > 0) { - $message .= ' Enabled extensions: ' . implode(', ', array_keys(array_filter($codebase->config->php_extensions))); + $enabled_extensions_names = array_keys(array_filter($codebase->config->php_extensions)); + $message .= ' Enabled extensions: ' . implode(', ', $enabled_extensions_names); } if (count($unsupported_php_extensions) > 0) {