Skip to content

Commit c7cfa82

Browse files
authored
[CodeQuality] Ensure verify ClassReflection->hasConstructor() on MethodParametersAndReturnTypesResolver (#550)
1 parent 1bb0ce4 commit c7cfa82

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Source\ValueObjectWithoutConstructor;
7+
8+
final class SkipWithoutConstruct extends TestCase
9+
{
10+
public function test()
11+
{
12+
$valueObject = new ValueObjectWithoutConstructor(123.456, '123');
13+
}
14+
}
15+
16+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\ScalarArgumentToExpectedParamTypeRector\Source;
6+
7+
final class ValueObjectWithoutConstructor
8+
{
9+
}

rules/CodeQuality/Reflection/MethodParametersAndReturnTypesResolver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function resolveCallParameterTypes(MethodCall|StaticCall|New_ $callLike):
8181
}
8282

8383
$classReflection = $this->reflectionProvider->getClass($className);
84+
85+
if (! $classReflection->hasConstructor()) {
86+
return null;
87+
}
88+
8489
return $this->resolveParameterTypes($classReflection->getConstructor(), $classReflection);
8590
}
8691

@@ -130,6 +135,11 @@ public function resolveCallParameterNames(MethodCall|StaticCall|New_ $callLike):
130135
}
131136

132137
$classReflection = $this->reflectionProvider->getClass($className);
138+
139+
if (! $classReflection->hasConstructor()) {
140+
return [];
141+
}
142+
133143
return $this->resolveParameterNames($classReflection->getConstructor());
134144
}
135145

0 commit comments

Comments
 (0)