1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Merge branch 'vimeo:master' into master

This commit is contained in:
Emmanuel Guiton 2023-01-11 13:17:45 +01:00 committed by GitHub
commit a7c60072dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 7 deletions

View File

@ -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.
*
@ -2158,7 +2225,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 <enableExtensions> directive in Psalm config.\n");
. " or use <enableExtensions> and/or <disableExtensions> directives in Psalm config.\n");
}
}

View File

@ -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,28 @@ 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) {
$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

View File

@ -592,11 +592,15 @@ class FunctionLikeNodeScanner
$var_comment_readonly = false;
$var_comment_allow_private_mutation = false;
if ($doc_comment) {
$template_types = ($this->existing_function_template_types ?: [])
+ ($classlike_storage->template_types ?: [])
;
$var_comments = CommentAnalyzer::getTypeFromComment(
$doc_comment,
$this->file_scanner,
$this->aliases,
$this->existing_function_template_types ?: [],
$template_types,
$this->type_aliases,
);

View File

@ -4029,6 +4029,28 @@ class ClassTemplateTest extends TestCase
$baz = new DoesNotExist();
foobar($baz);',
],
'promoted property with template' => [
'code' => '<?php
/**
* @template T
*/
class A {
public function __construct(
/** @var T */
public mixed $t
) {}
}
$a = new A(5);
$t = $a->t;
',
'assertions' => [
'$a' => 'A<int>',
'$t' => 'int',
],
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}