1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Merge pull request #10598 from weirdan/key_exists-is-an-alias-for-array_key_exists

This commit is contained in:
Bruce Weirdan 2024-01-29 16:23:35 -04:00 committed by GitHub
commit f045730927
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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,
],
];
}