1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Remove argc and argv elements from $_ENV

Fixes vimeo/psalm#8662
This commit is contained in:
Bruce Weirdan 2022-11-05 15:19:21 -04:00
parent 1e454fa3d5
commit 81423dc12b
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 19 additions and 4 deletions

View File

@ -650,11 +650,9 @@ class VariableFetchAnalyzer
$bool_string_helper = new Union([new TBool(), new TString()]); $bool_string_helper = new Union([new TBool(), new TString()]);
$bool_string_helper->possibly_undefined = true; $bool_string_helper->possibly_undefined = true;
$detailed_type = new TKeyedArray([ $detailed_type_members = [
// https://www.php.net/manual/en/reserved.variables.server.php // https://www.php.net/manual/en/reserved.variables.server.php
'PHP_SELF' => $non_empty_string_helper, 'PHP_SELF' => $non_empty_string_helper,
'argv' => $argv_helper,
'argc' => $argc_helper,
'GATEWAY_INTERFACE' => $non_empty_string_helper, 'GATEWAY_INTERFACE' => $non_empty_string_helper,
'SERVER_ADDR' => $non_empty_string_helper, 'SERVER_ADDR' => $non_empty_string_helper,
'SERVER_NAME' => $non_empty_string_helper, 'SERVER_NAME' => $non_empty_string_helper,
@ -727,7 +725,15 @@ class VariableFetchAnalyzer
// phpunit // phpunit
'APP_DEBUG' => $bool_string_helper, 'APP_DEBUG' => $bool_string_helper,
'APP_ENV' => $string_helper, 'APP_ENV' => $string_helper,
]); ];
if ($var_id === '$_SERVER') {
// those elements are not usually present in $_ENV
$detailed_type_members['argc'] = $argc_helper;
$detailed_type_members['argv'] = $argv_helper;
}
$detailed_type = new TKeyedArray($detailed_type_members);
// generic case for all other elements // generic case for all other elements
$detailed_type->previous_key_type = Type::getNonEmptyString(); $detailed_type->previous_key_type = Type::getNonEmptyString();

View File

@ -22,5 +22,14 @@ class SuperGlobalsTest extends TestCase
', ',
'assertions' => [] 'assertions' => []
]; ];
yield 'ENV has scalar entries only' => [
'<?php
/** @return array<array-key, scalar> */
function f(): array {
return $_ENV;
}
'
];
} }
} }