1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00

key_exists() is an alias for array_key_exists()

Fixes vimeo/psalm#10346
This commit is contained in:
Bruce Weirdan 2024-01-27 13:41:43 +01:00
parent 294220c744
commit 6e2effaf9a
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 16 additions and 1 deletions

View File

@ -2055,7 +2055,9 @@ final class AssertionFinder
protected static function hasArrayKeyExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool
{
return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'array_key_exists';
return $stmt->name instanceof PhpParser\Node\Name
&& (strtolower($stmt->name->getFirst()) === 'array_key_exists'
|| strtolower($stmt->name->getFirst()) === 'key_exists');
}
/**

View File

@ -507,6 +507,19 @@ class ArrayKeyExistsTest extends TestCase
'ignored_issues' => [],
'php_version' => '8.0',
],
'keyExistsAsAliasForArrayKeyExists' => [
'code' => <<<'PHP'
<?php
/**
* @param array<string, string> $arr
*/
function foo(array $arr): void {
if (key_exists("a", $arr)) {
echo $arr["a"];
}
}
PHP,
],
];
}