Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/set/php85.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use PhpParser\Node\Expr\Cast\String_;
use Rector\Config\RectorConfig;
use Rector\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector;
use Rector\Php85\Rector\ClassMethod\NullDebugInfoReturnRector;
use Rector\Php85\Rector\Class_\SleepToSerializeRector;
use Rector\Php85\Rector\ClassMethod\NullDebugInfoReturnRector;
use Rector\Php85\Rector\Const_\DeprecatedAnnotationToDeprecatedAttributeRector;
use Rector\Php85\Rector\FuncCall\ArrayKeyExistsNullToEmptyStringRector;
use Rector\Php85\Rector\FuncCall\ChrArgModuloRector;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

final class DifferentNamed
{
public function run()
{
preg_split('#a#', null, flags: 0);
}
}

?>
-----
<?php

namespace Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

final class DifferentNamed
{
public function run()
{
preg_split('#a#', '', flags: 0);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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;
Expand All @@ -31,7 +30,6 @@ final class NullToStrictStringFuncCallArgRector extends AbstractRector implement
{
public function __construct(
private readonly ReflectionResolver $reflectionResolver,
private readonly ArgsAnalyzer $argsAnalyzer,
private readonly NullToStrictStringIntConverter $nullToStrictStringIntConverter
) {
}
Expand Down Expand Up @@ -89,9 +87,7 @@ public function refactor(Node $node): ?Node
}

$args = $node->getArgs();
$positions = $this->argsAnalyzer->hasNamedArg($args)
? $this->resolveNamedPositions($node, $args)
: $this->resolveOriginalPositions($node, $scope);
$positions = $this->resolvePositions($node, $args, $scope);

if ($positions === []) {
return null;
Expand Down Expand Up @@ -139,11 +135,13 @@ public function provideMinPhpVersion(): int
* @param Arg[] $args
* @return int[]|string[]
*/
private function resolveNamedPositions(FuncCall $funcCall, array $args): array
private function resolvePositions(FuncCall $funcCall, array $args, Scope $scope): array
{
$positions = [];

$functionName = $this->getName($funcCall);
$argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES[$functionName] ?? [];
$positions = [];
$excludedArgNames = [];

foreach ($args as $position => $arg) {
if (! $arg->name instanceof Identifier) {
Expand All @@ -154,20 +152,13 @@ private function resolveNamedPositions(FuncCall $funcCall, array $args): array
continue;
}

$excludedArgNames[] = $arg->name->toString();
$positions[] = $position;
}

return $positions;
}

/**
* @return int[]|string[]
*/
private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope): array
{
$functionReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($funcCall);
if (! $functionReflection instanceof NativeFunctionReflection) {
return [];
return $positions;
}

$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select(
Expand All @@ -177,10 +168,10 @@ private function resolveOriginalPositions(FuncCall $funcCall, Scope $scope): arr
);
$functionName = $functionReflection->getName();
$argNames = NameNullToStrictNullFunctionMap::FUNCTION_TO_PARAM_NAMES[$functionName];
$positions = [];

foreach ($parametersAcceptor->getParameters() as $position => $parameterReflection) {
if (in_array($parameterReflection->getName(), $argNames, true)) {
if (in_array($parameterReflection->getName(), $argNames, true)
&& ! in_array($parameterReflection->getName(), $excludedArgNames, true)) {
$positions[] = $position;
}
}
Expand Down
4 changes: 2 additions & 2 deletions rules/Php85/Rector/Class_/SleepToSerializeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Rector\Php85\Rector\Class_;

use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\PhpParser\Node\BetterNodeFinder;
Expand Down
2 changes: 1 addition & 1 deletion src/ValueObject/PhpVersionFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ final class PhpVersionFeature
* @var int
*/
public const DEPRECATED_METHOD_SLEEP = PhpVersion::PHP_85;

/**
* @see https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_string_which_are_not_one_byte_long_to_ord
* @var int
Expand Down
Loading