Skip to content

Commit

Permalink
Merge pull request #9089 from lptn/cleaunup-unsupported-extentions-me…
Browse files Browse the repository at this point in the history
…ssage

Cleanup unsupported extensions message
  • Loading branch information
orklah committed Jan 10, 2023
2 parents 4e64745 + 3b5d1a4 commit 6bcd3bf
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
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 = [
'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
28 changes: 23 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,28 @@ 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) {
$enabled_extensions_names = array_keys(array_filter($codebase->config->php_extensions));
$message .= ' Enabled extensions: ' . implode(', ', $enabled_extensions_names);
}

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

0 comments on commit 6bcd3bf

Please sign in to comment.