diff --git a/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_already_set_encoding_named_arg.php.inc b/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_already_set_encoding_named_arg.php.inc new file mode 100644 index 00000000000..d1873d0a2b3 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_already_set_encoding_named_arg.php.inc @@ -0,0 +1,21 @@ + +----- + diff --git a/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php b/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php index 1183841edc3..1c240b07721 100644 --- a/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php +++ b/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php @@ -49,24 +49,23 @@ public function refactor(Node $node): ?Node return null; } - if (! isset($node->args[2])) { + // encoding already passed, positionally or by name + if ($node->getArg('encoding', 3) instanceof Arg) { return null; } - if (isset($node->args[3])) { + $offsetArg = $node->getArg('offset', 2); + if (! $offsetArg instanceof Arg) { return null; } - if (! $node->args[2] instanceof Arg) { + // only string can be an encoding; mixed/unknown can be the int $offset + $offsetArgType = $this->nodeTypeResolver->getNativeType($offsetArg->value); + if (! $offsetArgType->isString()->yes()) { return null; } - $secondArgType = $this->getType($node->args[2]->value); - if ($secondArgType->isInteger()->yes()) { - return null; - } - - $node->args[3] = $node->args[2]; + $node->args[3] = $offsetArg; $node->args[2] = new Arg(new Int_(0)); return $node;