mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
Updated Rector to commit 7294e98a19531d580c3ba901c147ea0a52282595
7294e98a19
Fix AddMethodCallBasedStrictParamTypeRector if already has a type (#5530)
This commit is contained in:
parent
4d9655bcf0
commit
aace6ea006
@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
@ -69,6 +70,10 @@ final class ClassMethodParamTypeCompleter
|
||||
if (!$this->isAcceptedByDefault($param, $argumentStaticType)) {
|
||||
continue;
|
||||
}
|
||||
// skip if param type already filled
|
||||
if ($param->type instanceof Identifier) {
|
||||
continue;
|
||||
}
|
||||
if ($param->type instanceof Name && $param->type->getAttribute(AttributeKey::VIRTUAL_NODE) === \true) {
|
||||
continue;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ final class AddMethodCallBasedStrictParamTypeRector extends AbstractRector
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Change private method param type to strict type, based on passed strict types', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
return new RuleDefinition('Change private classMethod param type to strict type, based on passed strict types', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class SomeClass
|
||||
{
|
||||
public function run(int $value)
|
||||
@ -88,20 +88,19 @@ CODE_SAMPLE
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($node->getMethods() as $method) {
|
||||
if ($method->params === []) {
|
||||
foreach ($node->getMethods() as $classMethod) {
|
||||
if ($classMethod->params === []) {
|
||||
continue;
|
||||
}
|
||||
$isPrivate = $node->isFinal() && !$node->extends instanceof Name && $node->implements === [] && $method->isProtected() || $method->isFinal() && !$node->extends instanceof Name && $node->implements === [] || $method->isPrivate();
|
||||
if (!$isPrivate) {
|
||||
if (!$this->isClassMethodPrivate($node, $classMethod)) {
|
||||
continue;
|
||||
}
|
||||
if ($method->isPublic()) {
|
||||
if ($classMethod->isPublic()) {
|
||||
continue;
|
||||
}
|
||||
$methodCalls = $this->localMethodCallFinder->match($node, $method);
|
||||
$methodCalls = $this->localMethodCallFinder->match($node, $classMethod);
|
||||
$classMethodParameterTypes = $this->callTypesResolver->resolveStrictTypesFromCalls($methodCalls);
|
||||
$classMethod = $this->classMethodParamTypeCompleter->complete($method, $classMethodParameterTypes, self::MAX_UNION_TYPES);
|
||||
$classMethod = $this->classMethodParamTypeCompleter->complete($classMethod, $classMethodParameterTypes, self::MAX_UNION_TYPES);
|
||||
if ($classMethod instanceof ClassMethod) {
|
||||
$hasChanged = \true;
|
||||
}
|
||||
@ -111,4 +110,14 @@ CODE_SAMPLE
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private function isClassMethodPrivate(Class_ $class, ClassMethod $classMethod) : bool
|
||||
{
|
||||
if ($classMethod->isPrivate()) {
|
||||
return \true;
|
||||
}
|
||||
if ($classMethod->isFinal() && !$class->extends instanceof Name && $class->implements === []) {
|
||||
return \true;
|
||||
}
|
||||
return $class->isFinal() && !$class->extends instanceof Name && $class->implements === [] && $classMethod->isProtected();
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'daf8b4879cbd0c4a0f42691b81b8d0c7f63da855';
|
||||
public const PACKAGE_VERSION = '7294e98a19531d580c3ba901c147ea0a52282595';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-30 22:47:15';
|
||||
public const RELEASE_DATE = '2024-01-30 23:55:11';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user