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

Added array_key_first and array_key_last stubs (#2381)

This commit is contained in:
Valentin Udaltsov 2019-11-27 18:59:12 +03:00 committed by Matthew Brown
parent 113bf921f6
commit 4a742f9940
2 changed files with 46 additions and 0 deletions

View File

@ -114,6 +114,32 @@ function key($arr)
{ {
} }
/**
* @psalm-template TKey as array-key
*
* @param array<TKey, mixed> $arr
*
* @return TKey|null
* @psalm-ignore-nullable-return
* @psalm-pure
*/
function array_key_first($arr)
{
}
/**
* @psalm-template TKey as array-key
*
* @param array<TKey, mixed> $arr
*
* @return TKey|null
* @psalm-ignore-nullable-return
* @psalm-pure
*/
function array_key_last($arr)
{
}
/** /**
* @psalm-template T * @psalm-template T
* *

View File

@ -1022,6 +1022,26 @@ class FunctionCallTest extends TestCase
'$c' => 'int', '$c' => 'int',
], ],
], ],
'array_key_first' => [
'<?php
$a = ["one" => 1, "two" => 3];
$b = array_key_first($a);
$c = $a[$b];',
'assertions' => [
'$b' => 'null|string',
'$c' => 'int',
],
],
'array_key_last' => [
'<?php
$a = ["one" => 1, "two" => 3];
$b = array_key_last($a);
$c = $a[$b];',
'assertions' => [
'$b' => 'null|string',
'$c' => 'int',
],
],
'explode' => [ 'explode' => [
'<?php '<?php
/** @var string $string */ /** @var string $string */