Skip to content

Commit e46fb7c

Browse files
committed
Updated Rector to commit 30ecb365512dc3332703e46ce2da8c1acad1c268
rectorphp/rector-src@30ecb36 [TypeDeclaration] Handle crash on return different over static on AddReturnTypeDeclarationRector-a (#6943)
1 parent 6dedccb commit e46fb7c

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
namespace Rector\TypeDeclaration\Rector\ClassMethod;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Name;
87
use PhpParser\Node\Stmt\Class_;
98
use PhpParser\Node\Stmt\ClassMethod;
9+
use PHPStan\Reflection\ClassReflection;
1010
use PHPStan\Type\ArrayType;
1111
use PHPStan\Type\MixedType;
1212
use PHPStan\Type\ObjectType;
13+
use PHPStan\Type\StaticType;
1314
use PHPStan\Type\Type;
1415
use Rector\Contract\Rector\ConfigurableRectorInterface;
1516
use Rector\Php\PhpVersionProvider;
1617
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
1718
use Rector\Rector\AbstractRector;
19+
use Rector\Reflection\ReflectionResolver;
1820
use Rector\StaticTypeMapper\StaticTypeMapper;
1921
use Rector\StaticTypeMapper\ValueObject\Type\SimpleStaticType;
2022
use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration;
@@ -40,16 +42,21 @@ final class AddReturnTypeDeclarationRector extends AbstractRector implements Con
4042
* @readonly
4143
*/
4244
private StaticTypeMapper $staticTypeMapper;
45+
/**
46+
* @readonly
47+
*/
48+
private ReflectionResolver $reflectionResolver;
4349
/**
4450
* @var AddReturnTypeDeclaration[]
4551
*/
4652
private array $methodReturnTypes = [];
4753
private bool $hasChanged = \false;
48-
public function __construct(PhpVersionProvider $phpVersionProvider, ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, StaticTypeMapper $staticTypeMapper)
54+
public function __construct(PhpVersionProvider $phpVersionProvider, ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, StaticTypeMapper $staticTypeMapper, ReflectionResolver $reflectionResolver)
4955
{
5056
$this->phpVersionProvider = $phpVersionProvider;
5157
$this->parentClassMethodTypeOverrideGuard = $parentClassMethodTypeOverrideGuard;
5258
$this->staticTypeMapper = $staticTypeMapper;
59+
$this->reflectionResolver = $reflectionResolver;
5360
}
5461
public function getRuleDefinition() : RuleDefinition
5562
{
@@ -123,8 +130,12 @@ private function processClassMethodNodeWithTypehints(ClassMethod $classMethod, C
123130
$classMethod->returnType = null;
124131
return;
125132
}
126-
if ($newType instanceof SimpleStaticType && $classMethod->returnType instanceof Name && $this->isName($classMethod->returnType, 'static')) {
127-
return;
133+
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
134+
if ($classMethod->returnType instanceof Node && $newType instanceof SimpleStaticType) {
135+
if (!$classReflection instanceof ClassReflection) {
136+
return;
137+
}
138+
$newType = new StaticType($classReflection);
128139
}
129140
// already set and sub type or equal → no change
130141
if ($this->parentClassMethodTypeOverrideGuard->shouldSkipReturnTypeChange($classMethod, $newType)) {

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'c7278fa576a22288228814bc2b20bd0cddea4677';
22+
public const PACKAGE_VERSION = '30ecb365512dc3332703e46ce2da8c1acad1c268';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-05-29 09:00:48';
27+
public const RELEASE_DATE = '2025-05-29 04:55:10';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)