From d1d696028219d9dd97d0799ee5cac2882e243afd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 3 Nov 2026 15:50:54 +0700 Subject: [PATCH 1/3] [Php74] Fix MbStrrposEncodingArgumentPositionRector treating mixed $offset as encoding --- .../Fixture/skip_mixed_offset.php.inc | 16 +++++++++++ .../Fixture/string_encoding_variable.php.inc | 27 +++++++++++++++++++ ...bStrrposEncodingArgumentPositionRector.php | 10 +++++-- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_mixed_offset.php.inc create mode 100644 rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/string_encoding_variable.php.inc diff --git a/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_mixed_offset.php.inc b/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_mixed_offset.php.inc new file mode 100644 index 00000000000..9ed63b20370 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_mixed_offset.php.inc @@ -0,0 +1,16 @@ + +----- + diff --git a/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php b/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php index 1183841edc3..ab967fed94d 100644 --- a/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php +++ b/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\Int_; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -61,8 +62,13 @@ public function refactor(Node $node): ?Node return null; } - $secondArgType = $this->getType($node->args[2]->value); - if ($secondArgType->isInteger()->yes()) { + if ($node->args[2]->name instanceof Identifier) { + return null; + } + + // only string can be an encoding; mixed/unknown can be the int $offset + $thirdArgType = $this->nodeTypeResolver->getNativeType($node->args[2]->value); + if (! $thirdArgType->isString()->yes()) { return null; } From ec98e4383ef273777dae7e76acbbd35b5b0842b3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 3 Nov 2026 15:55:31 +0700 Subject: [PATCH 2/3] use check --- .../Fixture/skip_spread_or_docblock.php.inc | 24 +++++++++++++++++++ ...bStrrposEncodingArgumentPositionRector.php | 21 ++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_spread_or_docblock.php.inc diff --git a/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_spread_or_docblock.php.inc b/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_spread_or_docblock.php.inc new file mode 100644 index 00000000000..fca0cace683 --- /dev/null +++ b/rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_spread_or_docblock.php.inc @@ -0,0 +1,24 @@ +args[2])) { + // encoding already passed, positionally or by name + if ($node->getArg('encoding', 3) instanceof Arg) { return null; } - if (isset($node->args[3])) { - return null; - } - - if (! $node->args[2] instanceof Arg) { - return null; - } - - if ($node->args[2]->name instanceof Identifier) { + $offsetArg = $node->getArg('offset', 2); + if (! $offsetArg instanceof Arg) { return null; } // only string can be an encoding; mixed/unknown can be the int $offset - $thirdArgType = $this->nodeTypeResolver->getNativeType($node->args[2]->value); - if (! $thirdArgType->isString()->yes()) { + $offsetArgType = $this->nodeTypeResolver->getNativeType($offsetArg->value); + if (! $offsetArgType->isString()->yes()) { return null; } - $node->args[3] = $node->args[2]; + $node->args[3] = $offsetArg; $node->args[2] = new Arg(new Int_(0)); return $node; From c9f8b8ba93271829d08242a0b3320368bdfcee6f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 3 Nov 2026 15:58:04 +0700 Subject: [PATCH 3/3] extract fixtures --- ...kip_already_set_encoding_named_arg.php.inc | 21 +++++++++++++++++++ .../Fixture/skip_mixed_offset.php.inc | 5 ----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 rules-tests/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector/Fixture/skip_already_set_encoding_named_arg.php.inc 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 @@ +