From 006f788d6a5b7b605e35822a6dff2ff1c054b4a7 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Fri, 27 Dec 2019 16:30:42 +0300 Subject: [PATCH] Added array_fill_keys support (#2512) * Added array_fill_keys support * Removed unnecessary array_fill_keys phpdoc --- src/Psalm/Internal/Analyzer/ProjectAnalyzer.php | 1 - src/Psalm/Internal/Fork/Pool.php | 1 - src/Psalm/Internal/Stubs/CoreGenericFunctions.php | 14 ++++++++++++++ tests/FunctionCallTest.php | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 1f3bff497..f44ab86de 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -1187,7 +1187,6 @@ class ProjectAnalyzer public function setAllIssuesToFix(): void { - /** @var array $keyed_issues */ $keyed_issues = array_fill_keys(static::getSupportedIssuesToFix(), true); $this->setIssuesToFix($keyed_issues); diff --git a/src/Psalm/Internal/Fork/Pool.php b/src/Psalm/Internal/Fork/Pool.php index f0027ff8f..d08895dc3 100644 --- a/src/Psalm/Internal/Fork/Pool.php +++ b/src/Psalm/Internal/Fork/Pool.php @@ -287,7 +287,6 @@ class Pool // Create an array for the content received on each stream, // indexed by resource id. - /** @var array $content */ $content = array_fill_keys(array_keys($streams), ''); $terminationMessages = []; diff --git a/src/Psalm/Internal/Stubs/CoreGenericFunctions.php b/src/Psalm/Internal/Stubs/CoreGenericFunctions.php index 6586a4741..58aa04fbd 100644 --- a/src/Psalm/Internal/Stubs/CoreGenericFunctions.php +++ b/src/Psalm/Internal/Stubs/CoreGenericFunctions.php @@ -217,3 +217,17 @@ function array_key_exists($key, array $search) : bool function array_merge_recursive(array $arr, array ...$arr2) { } + +/** + * @psalm-template TKey as array-key + * @psalm-template TValue + * + * @param array $keys + * @param TValue $value + * + * @return array + * @psalm-pure + */ +function array_fill_keys(array $keys, $value): array +{ +} diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index b614e577f..898e339fa 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -2334,6 +2334,14 @@ class FunctionCallTest extends TestCase ); }' ], + 'arrayFillKeys' => [ + ' [ + '$result' => 'array', + ], + ], ]; }