Skip to content

Commit

Permalink
Added array_key_first and array_key_last stubs (#2381)
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov authored and muglug committed Nov 27, 2019
1 parent 113bf92 commit 4a742f9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Psalm/Internal/Stubs/CoreGenericFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
20 changes: 20 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,26 @@ public static function Baz($mixed) : string {
'$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' => [
'<?php
/** @var string $string */
Expand Down

0 comments on commit 4a742f9

Please sign in to comment.