Add Rector to replace null keys in array_key_exists with empty string#7180
Add Rector to replace null keys in array_key_exists with empty string#7180arshidkv12 wants to merge 7 commits intorectorphp:mainfrom
Conversation
| if (! $node instanceof FuncCall) { | ||
| return null; | ||
| } | ||
|
|
There was a problem hiding this comment.
add skip early $node->isFirstClassCallable() early here
| return null; | ||
| } | ||
|
|
||
| if ($this->isName($keyExpr, 'null')) { |
There was a problem hiding this comment.
use valueResolver->isNull instead, ensure exactly null variable, not variable named null
| return $node; | ||
| } | ||
|
|
||
| return $node; |
| CODE_SAMPLE | ||
| , | ||
| <<<'CODE_SAMPLE' | ||
| array_key_exists($key ?? '', $array); |
There was a problem hiding this comment.
I prefer check type, if not string, then use (string) cast instead, see other rule
There was a problem hiding this comment.
Since the logic seems similar, I think you can create re-usable service to be used in both NullToStrictStringFuncCallArgRector and this rule so it share similar behaviour, just different php version and function.
There was a problem hiding this comment.
Does it need Rector\Php85\Enum\NameNullToStrictNullFunctionMap, and should only array_key_exists be added?
Or without Rector\Php85\Enum\NameNullToStrictNullFunctionMap?
There was a problem hiding this comment.
for just single function, no need to add to enum imo
| * @param Arg[] $args | ||
| * @param int|string $position | ||
| */ | ||
| private function processNullToStrictStringOnNodePosition( |
There was a problem hiding this comment.
this method looks duplicated with NullToStrictStringFuncCallArgRector, can be moved to shared service imo
There was a problem hiding this comment.
I think I should create a class like this, right?
final class NullToStrictStringConverter
{
public function convertIfNull(Node $expr): Node
{}
}Where should I put it?”
There was a problem hiding this comment.
Yes, on Php81 namespace since it start there
https://github.com/rectorphp/rector-src/tree/main/rules/Php81/NodeManipulator
|
This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work. |
PHP 8.5+ deprecates passing null as the key to
array_key_exists().This Rector rule automatically replaces:
with:
https://wiki.php.net/rfc/deprecations_php_8_5