From e6f3ac6e0a282ef86207132c29ed57ef026b8ee1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 11 Sep 2025 10:41:15 +0700 Subject: [PATCH 1/7] [Php81] Add NullToStrictIntPregSlitFuncCallLimitArgRector --- .../Fixture/fixture.php.inc | 27 +++ ...tIntPregSlitFuncCallLimitArgRectorTest.php | 28 +++ .../config/configured_rule.php | 9 + ...php => NullToStrictStringIntConverter.php} | 31 ++- ...trictIntPregSlitFuncCallLimitArgRector.php | 188 ++++++++++++++++++ .../NullToStrictStringFuncCallArgRector.php | 3 +- 6 files changed, 275 insertions(+), 11 deletions(-) create mode 100644 rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/fixture.php.inc create mode 100644 rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/NullToStrictIntPregSlitFuncCallLimitArgRectorTest.php create mode 100644 rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/config/configured_rule.php rename rules/Php81/NodeManipulator/{NullToStrictStringConverter.php => NullToStrictStringIntConverter.php} (82%) create mode 100644 rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php diff --git a/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/fixture.php.inc b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/fixture.php.inc new file mode 100644 index 00000000000..ee7ae7a818b --- /dev/null +++ b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/fixture.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/NullToStrictIntPregSlitFuncCallLimitArgRectorTest.php b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/NullToStrictIntPregSlitFuncCallLimitArgRectorTest.php new file mode 100644 index 00000000000..74c4a8b1628 --- /dev/null +++ b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/NullToStrictIntPregSlitFuncCallLimitArgRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/config/configured_rule.php b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/config/configured_rule.php new file mode 100644 index 00000000000..7a7a0f036fa --- /dev/null +++ b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/config/configured_rule.php @@ -0,0 +1,9 @@ +withRules([NullToStrictIntPregSlitFuncCallLimitArgRector::class]); diff --git a/rules/Php81/NodeManipulator/NullToStrictStringConverter.php b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php similarity index 82% rename from rules/Php81/NodeManipulator/NullToStrictStringConverter.php rename to rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php index f11cbec523e..d13a73ba9d0 100644 --- a/rules/Php81/NodeManipulator/NullToStrictStringConverter.php +++ b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php @@ -6,10 +6,12 @@ use PhpParser\Node\Arg; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Cast\Int_ as CastInt_; use PhpParser\Node\Expr\Cast\String_ as CastString_; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Ternary; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node\Scalar\String_; use PHPStan\Analyser\Scope; @@ -24,7 +26,7 @@ use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\PhpParser\Node\Value\ValueResolver; -final readonly class NullToStrictStringConverter +final readonly class NullToStrictStringIntConverter { public function __construct( private ValueResolver $valueResolver, @@ -42,7 +44,8 @@ public function convertIfNull( int $position, bool $isTrait, Scope $scope, - ParametersAcceptor $parametersAcceptor + ParametersAcceptor $parametersAcceptor, + string $type = 'string' ): ?FuncCall { if (! isset($args[$position])) { return null; @@ -50,12 +53,12 @@ public function convertIfNull( $argValue = $args[$position]->value; if ($this->valueResolver->isNull($argValue)) { - $args[$position]->value = new String_(''); + $args[$position]->value = $type === 'string' ? new String_('') : new Int_(0); $funcCall->args = $args; return $funcCall; } - if ($this->shouldSkipValue($argValue, $scope, $isTrait)) { + if ($this->shouldSkipValue($argValue, $scope, $isTrait, $type)) { return null; } @@ -67,11 +70,11 @@ public function convertIfNull( } } - if ($argValue instanceof Ternary && ! $this->shouldSkipValue($argValue->else, $scope, $isTrait)) { + if ($argValue instanceof Ternary && ! $this->shouldSkipValue($argValue->else, $scope, $isTrait, $type)) { if ($this->valueResolver->isNull($argValue->else)) { - $argValue->else = new String_(''); + $argValue->else = $type === 'string' ? new String_('') : new Int_(0); } else { - $argValue->else = new CastString_($argValue->else); + $argValue->else = $type === 'string' ? new CastString_($argValue->else) : new CastInt_($argValue->else); } $args[$position]->value = $argValue; @@ -84,15 +87,23 @@ public function convertIfNull( return $funcCall; } - private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait): bool + private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait, string $type): bool { $type = $this->nodeTypeResolver->getType($expr); - if ($type->isString()->yes()) { + if ($type->isString()->yes() && $type === 'string') { + return true; + } + + if ($type->isInteger()->yes() && $type === 'int') { return true; } $nativeType = $this->nodeTypeResolver->getNativeType($expr); - if ($nativeType->isString()->yes()) { + if ($nativeType->isString()->yes() && $type === 'string') { + return true; + } + + if ($nativeType->isInteger()->yes() && $type === 'int') { return true; } diff --git a/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php new file mode 100644 index 00000000000..7986c5a3baa --- /dev/null +++ b/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php @@ -0,0 +1,188 @@ +> + */ + public function getNodeTypes(): array + { + return [FuncCall::class]; + } + + /** + * @param FuncCall $node + */ + public function refactor(Node $node): ?Node + { + if ($this->shouldSkip($node)) { + return null; + } + + $scope = $node->getAttribute(AttributeKey::SCOPE); + if (! $scope instanceof Scope) { + return null; + } + + $args = $node->getArgs(); + $position = $this->argsAnalyzer->hasNamedArg($args) + ? $this->resolveNamedPosition($args) + : 2; + + if ($position === null) { + return null; + } + + $classReflection = $scope->getClassReflection(); + $isTrait = $classReflection instanceof ClassReflection && $classReflection->isTrait(); + + $functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); + if (! $functionReflection instanceof FunctionReflection) { + return null; + } + + $parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($functionReflection, $node, $scope); + $result = $this->nullToStrictStringConverter->convertIfNull( + $node, + $args, + (int) $position, + $isTrait, + $scope, + $parametersAcceptor, + 'int' + ); + + if ($result instanceof Node) { + return $result; + } + + return null; + } + + public function provideMinPhpVersion(): int + { + return PhpVersionFeature::DEPRECATE_NULL_ARG_IN_STRING_FUNCTION; + } + + /** + * @param Arg[] $args + * @return ?int + */ + private function resolveNamedPosition(array $args): ?int + { + foreach ($args as $position => $arg) { + if (! $arg->name instanceof Identifier) { + continue; + } + + if (! $this->isName($arg->name, 'limit')) { + continue; + } + + return $position; + } + + return null; + } + + /** + * @return int[]|string[] + */ + private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope): array + { + $functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($funcCall); + if (! $functionReflection instanceof NativeFunctionReflection) { + return []; + } + + $parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select( + $functionReflection, + $funcCall, + $scope + ); + $functionName = $functionReflection->getName(); + $argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES[$functionName]; + $positions = []; + + foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) { + if (in_array($parameterReflection->getName(), $argNames, true)) { + $positions[] = $position; + } + } + + return $positions; + } + + private function shouldSkip(FuncCall $funcCall): bool + { + if (! $this->isName($funcCall, 'preg_split')) { + return true; + } + + return $funcCall->isFirstClassCallable(); + } +} diff --git a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php index b4b177ee061..08171002fbe 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php @@ -17,6 +17,7 @@ use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper; use Rector\Php81\Enum\NameNullToStrictNullFunctionMap; use Rector\Php81\NodeManipulator\NullToStrictStringConverter; +use Rector\Php81\NodeManipulator\NullToStrictStringIntConverter; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; use Rector\ValueObject\PhpVersionFeature; @@ -32,7 +33,7 @@ final class NullToStrictStringFuncCallArgRector extends AbstractRector implement public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly ArgsAnalyzer $argsAnalyzer, - private readonly NullToStrictStringConverter $nullToStrictStringConverter + private readonly NullToStrictStringIntConverter $nullToStrictStringConverter ) { } From 846cc8c38cd4537af00b6be65ba6652f8f16b424 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 11 Sep 2025 10:45:30 +0700 Subject: [PATCH 2/7] rectify --- .../NullToStrictStringIntConverter.php | 2 +- ...trictIntPregSlitFuncCallLimitArgRector.php | 38 ++----------------- .../NullToStrictStringFuncCallArgRector.php | 5 +-- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php index d13a73ba9d0..30e029cf834 100644 --- a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php +++ b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php @@ -82,7 +82,7 @@ public function convertIfNull( return $funcCall; } - $args[$position]->value = new CastString_($argValue); + $args[$position]->value = $type === 'string' ? new CastString_($argValue) : new CastInt_($argValue); $funcCall->args = $args; return $funcCall; } diff --git a/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php index 7986c5a3baa..b756e19954f 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php @@ -11,11 +11,9 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\FunctionReflection; -use PHPStan\Reflection\Native\NativeFunctionReflection; use Rector\NodeAnalyzer\ArgsAnalyzer; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper; -use Rector\Php81\Enum\NameNullToStrictNullFunctionMap; use Rector\Php81\NodeManipulator\NullToStrictStringIntConverter; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; @@ -25,6 +23,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** + * @see https://3v4l.org/cVPim * @see \Rector\Tests\Php81\Rector\FuncCall\NullToStrictIntPregSlitFuncCallLimitArgRector\NullToStrictIntPregSlitFuncCallLimitArgRectorTest */ final class NullToStrictIntPregSlitFuncCallLimitArgRector extends AbstractRector implements MinPhpVersionInterface @@ -32,7 +31,7 @@ final class NullToStrictIntPregSlitFuncCallLimitArgRector extends AbstractRector public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly ArgsAnalyzer $argsAnalyzer, - private readonly NullToStrictStringIntConverter $nullToStrictStringConverter + private readonly NullToStrictStringIntConverter $nullToStrictStringIntConverter ) { } @@ -106,10 +105,10 @@ public function refactor(Node $node): ?Node } $parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($functionReflection, $node, $scope); - $result = $this->nullToStrictStringConverter->convertIfNull( + $result = $this->nullToStrictStringIntConverter->convertIfNull( $node, $args, - (int) $position, + $position, $isTrait, $scope, $parametersAcceptor, @@ -130,7 +129,6 @@ public function provideMinPhpVersion(): int /** * @param Arg[] $args - * @return ?int */ private function resolveNamedPosition(array $args): ?int { @@ -149,34 +147,6 @@ private function resolveNamedPosition(array $args): ?int return null; } - /** - * @return int[]|string[] - */ - private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope): array - { - $functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($funcCall); - if (! $functionReflection instanceof NativeFunctionReflection) { - return []; - } - - $parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select( - $functionReflection, - $funcCall, - $scope - ); - $functionName = $functionReflection->getName(); - $argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES[$functionName]; - $positions = []; - - foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) { - if (in_array($parameterReflection->getName(), $argNames, true)) { - $positions[] = $position; - } - } - - return $positions; - } - private function shouldSkip(FuncCall $funcCall): bool { if (! $this->isName($funcCall, 'preg_split')) { diff --git a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php index 08171002fbe..42abbafa38d 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictStringFuncCallArgRector.php @@ -16,7 +16,6 @@ use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper; use Rector\Php81\Enum\NameNullToStrictNullFunctionMap; -use Rector\Php81\NodeManipulator\NullToStrictStringConverter; use Rector\Php81\NodeManipulator\NullToStrictStringIntConverter; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; @@ -33,7 +32,7 @@ final class NullToStrictStringFuncCallArgRector extends AbstractRector implement public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly ArgsAnalyzer $argsAnalyzer, - private readonly NullToStrictStringIntConverter $nullToStrictStringConverter + private readonly NullToStrictStringIntConverter $nullToStrictStringIntConverter ) { } @@ -110,7 +109,7 @@ public function refactor(Node $node): ?Node $isChanged = false; foreach ($positions as $position) { - $result = $this->nullToStrictStringConverter->convertIfNull( + $result = $this->nullToStrictStringIntConverter->convertIfNull( $node, $args, (int) $position, From 021e7df261d7a1c1f05fa8fd4e9a361b0ef26da9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 11 Sep 2025 10:49:58 +0700 Subject: [PATCH 3/7] fix --- .../NullToStrictStringIntConverter.php | 24 +++++++++---------- .../ArrayKeyExistsNullToEmptyStringRector.php | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php index 30e029cf834..bb3b58518d9 100644 --- a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php +++ b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php @@ -45,7 +45,7 @@ public function convertIfNull( bool $isTrait, Scope $scope, ParametersAcceptor $parametersAcceptor, - string $type = 'string' + string $targetType = 'string' ): ?FuncCall { if (! isset($args[$position])) { return null; @@ -53,12 +53,12 @@ public function convertIfNull( $argValue = $args[$position]->value; if ($this->valueResolver->isNull($argValue)) { - $args[$position]->value = $type === 'string' ? new String_('') : new Int_(0); + $args[$position]->value = $targetType === 'string' ? new String_('') : new Int_(0); $funcCall->args = $args; return $funcCall; } - if ($this->shouldSkipValue($argValue, $scope, $isTrait, $type)) { + if ($this->shouldSkipValue($argValue, $scope, $isTrait, $targetType)) { return null; } @@ -70,11 +70,11 @@ public function convertIfNull( } } - if ($argValue instanceof Ternary && ! $this->shouldSkipValue($argValue->else, $scope, $isTrait, $type)) { + if ($argValue instanceof Ternary && ! $this->shouldSkipValue($argValue->else, $scope, $isTrait, $targetType)) { if ($this->valueResolver->isNull($argValue->else)) { - $argValue->else = $type === 'string' ? new String_('') : new Int_(0); + $argValue->else = $targetType === 'string' ? new String_('') : new Int_(0); } else { - $argValue->else = $type === 'string' ? new CastString_($argValue->else) : new CastInt_($argValue->else); + $argValue->else = $targetType === 'string' ? new CastString_($argValue->else) : new CastInt_($argValue->else); } $args[$position]->value = $argValue; @@ -82,28 +82,28 @@ public function convertIfNull( return $funcCall; } - $args[$position]->value = $type === 'string' ? new CastString_($argValue) : new CastInt_($argValue); + $args[$position]->value = $targetType === 'string' ? new CastString_($argValue) : new CastInt_($argValue); $funcCall->args = $args; return $funcCall; } - private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait, string $type): bool + private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait, string $targetType): bool { $type = $this->nodeTypeResolver->getType($expr); - if ($type->isString()->yes() && $type === 'string') { + if ($type->isString()->yes() && $targetType === 'string') { return true; } - if ($type->isInteger()->yes() && $type === 'int') { + if ($type->isInteger()->yes() && $targetType === 'int') { return true; } $nativeType = $this->nodeTypeResolver->getNativeType($expr); - if ($nativeType->isString()->yes() && $type === 'string') { + if ($nativeType->isString()->yes() && $targetType === 'string') { return true; } - if ($nativeType->isInteger()->yes() && $type === 'int') { + if ($nativeType->isInteger()->yes() && $targetType === 'int') { return true; } diff --git a/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php b/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php index b061f553d50..55ac2f33ac7 100644 --- a/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php +++ b/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php @@ -14,6 +14,7 @@ use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper; use Rector\Php81\NodeManipulator\NullToStrictStringConverter; +use Rector\Php81\NodeManipulator\NullToStrictStringIntConverter; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; use Rector\ValueObject\PhpVersionFeature; @@ -29,7 +30,7 @@ final class ArrayKeyExistsNullToEmptyStringRector extends AbstractRector impleme { public function __construct( private readonly ReflectionResolver $reflectionResolver, - private readonly NullToStrictStringConverter $nullToStrictStringConverter + private readonly NullToStrictStringIntConverter $nullToStrictStringConverter ) { } From 36ce153958f97181b1b088f7862c3fab9ddfdcc3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 11 Sep 2025 10:50:25 +0700 Subject: [PATCH 4/7] fix --- .../NullToStrictIntPregSlitFuncCallLimitArgRector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php b/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php index b756e19954f..db3b77d0e91 100644 --- a/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php +++ b/rules/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector.php @@ -96,6 +96,10 @@ public function refactor(Node $node): ?Node return null; } + if (! isset($args[$position])) { + return null; + } + $classReflection = $scope->getClassReflection(); $isTrait = $classReflection instanceof ClassReflection && $classReflection->isTrait(); From b11f7e87b008ac4a029099c28a2dfe061efeb9a1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 11 Sep 2025 10:51:42 +0700 Subject: [PATCH 5/7] fix --- .../Fixture/skip_no_limit.php.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/skip_no_limit.php.inc diff --git a/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/skip_no_limit.php.inc b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/skip_no_limit.php.inc new file mode 100644 index 00000000000..f0ca2ac91fa --- /dev/null +++ b/rules-tests/Php81/Rector/FuncCall/NullToStrictIntPregSlitFuncCallLimitArgRector/Fixture/skip_no_limit.php.inc @@ -0,0 +1,11 @@ + Date: Thu, 11 Sep 2025 10:52:37 +0700 Subject: [PATCH 6/7] Fix --- .../Php81/NodeManipulator/NullToStrictStringIntConverter.php | 4 +++- .../FuncCall/ArrayKeyExistsNullToEmptyStringRector.php | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php index bb3b58518d9..10be1ac45c0 100644 --- a/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php +++ b/rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php @@ -74,7 +74,9 @@ public function convertIfNull( if ($this->valueResolver->isNull($argValue->else)) { $argValue->else = $targetType === 'string' ? new String_('') : new Int_(0); } else { - $argValue->else = $targetType === 'string' ? new CastString_($argValue->else) : new CastInt_($argValue->else); + $argValue->else = $targetType === 'string' ? new CastString_($argValue->else) : new CastInt_( + $argValue->else + ); } $args[$position]->value = $argValue; diff --git a/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php b/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php index 55ac2f33ac7..9f2f649ead6 100644 --- a/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php +++ b/rules/Php85/Rector/FuncCall/ArrayKeyExistsNullToEmptyStringRector.php @@ -13,7 +13,6 @@ use PHPStan\Reflection\FunctionReflection; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper; -use Rector\Php81\NodeManipulator\NullToStrictStringConverter; use Rector\Php81\NodeManipulator\NullToStrictStringIntConverter; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; @@ -30,7 +29,7 @@ final class ArrayKeyExistsNullToEmptyStringRector extends AbstractRector impleme { public function __construct( private readonly ReflectionResolver $reflectionResolver, - private readonly NullToStrictStringIntConverter $nullToStrictStringConverter + private readonly NullToStrictStringIntConverter $nullToStrictStringIntConverter ) { } @@ -91,7 +90,7 @@ public function refactor(Node $node): ?Node $parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($functionReflection, $node, $scope); - $result = $this->nullToStrictStringConverter->convertIfNull( + $result = $this->nullToStrictStringIntConverter->convertIfNull( $node, $args, $this->resolvePosition($args), From b06559de13745dd57a427c27bdca396180a5e8c0 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 11 Sep 2025 10:57:06 +0700 Subject: [PATCH 7/7] register --- config/set/php81.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/set/php81.php b/config/set/php81.php index b87051387c8..a2f856a1c9c 100644 --- a/config/set/php81.php +++ b/config/set/php81.php @@ -6,6 +6,7 @@ use Rector\Php81\Rector\Array_\FirstClassCallableRector; use Rector\Php81\Rector\Class_\MyCLabsClassToEnumRector; use Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector; +use Rector\Php81\Rector\FuncCall\NullToStrictIntPregSlitFuncCallLimitArgRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; use Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector; use Rector\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector; @@ -24,6 +25,7 @@ SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NullToStrictStringFuncCallArgRector::class, + NullToStrictIntPregSlitFuncCallLimitArgRector::class, FirstClassCallableRector::class, RemoveReflectionSetAccessibleCallsRector::class, ]);