From 36e67dfbb599b33e6d205919bde958e25491d947 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 21 Sep 2025 20:28:39 +0700 Subject: [PATCH] [CodeQuality] Ensure verify ClassReflection->hasConstructor() on MethodParametersAndReturnTypesResolver --- .../Fixture/skip_without_construct.php.inc | 16 ++++++++++++++++ .../Source/ValueObjectWithoutConstructor.php | 9 +++++++++ .../MethodParametersAndReturnTypesResolver.php | 10 ++++++++++ 3 files changed, 35 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/skip_without_construct.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Source/ValueObjectWithoutConstructor.php diff --git a/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/skip_without_construct.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/skip_without_construct.php.inc new file mode 100644 index 00000000..c5e56375 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Fixture/skip_without_construct.php.inc @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Source/ValueObjectWithoutConstructor.php b/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Source/ValueObjectWithoutConstructor.php new file mode 100644 index 00000000..fd69eb9d --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/ScalarArgumentToExpectedParamTypeRector/Source/ValueObjectWithoutConstructor.php @@ -0,0 +1,9 @@ +reflectionProvider->getClass($className); + + if (! $classReflection->hasConstructor()) { + return null; + } + return $this->resolveParameterTypes($classReflection->getConstructor(), $classReflection); } @@ -130,6 +135,11 @@ public function resolveCallParameterNames(MethodCall|StaticCall|New_ $callLike): } $classReflection = $this->reflectionProvider->getClass($className); + + if (! $classReflection->hasConstructor()) { + return []; + } + return $this->resolveParameterNames($classReflection->getConstructor()); }