Skip to content

Commit 2fd54c2

Browse files
fixed deprecated reflection method
1 parent 2b21388 commit 2fd54c2

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

lib/internal/Magento/Framework/Code/Reader/ClassReader.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Framework\Code\Reader;
77

8+
use ReflectionClass;
9+
use ReflectionException;
10+
use ReflectionParameter;
11+
812
/**
913
* Class ClassReader
1014
*/
@@ -17,46 +21,62 @@ class ClassReader implements ClassReaderInterface
1721
*
1822
* @param string $className
1923
* @return array|null
20-
* @throws \ReflectionException
24+
* @throws ReflectionException
2125
*/
2226
public function getConstructor($className)
2327
{
24-
$class = new \ReflectionClass($className);
28+
$class = new ReflectionClass($className);
2529
$result = null;
2630
$constructor = $class->getConstructor();
2731
if ($constructor) {
2832
$result = [];
29-
/** @var $parameter \ReflectionParameter */
33+
/** @var $parameter ReflectionParameter */
3034
foreach ($constructor->getParameters() as $parameter) {
3135
try {
3236
$result[] = [
3337
$parameter->getName(),
34-
$parameter->getClass() !== null ? $parameter->getClass()->getName() : null,
38+
$this->getParameterClass($parameter),
3539
!$parameter->isOptional() && !$parameter->isDefaultValueAvailable(),
3640
$this->getReflectionParameterDefaultValue($parameter),
3741
$parameter->isVariadic(),
3842
];
39-
} catch (\ReflectionException $e) {
43+
} catch (ReflectionException $e) {
4044
$message = sprintf(
4145
'Impossible to process constructor argument %s of %s class',
4246
$parameter->__toString(),
4347
$className
4448
);
45-
throw new \ReflectionException($message, 0, $e);
49+
throw new ReflectionException($message, 0, $e);
4650
}
4751
}
4852
}
4953

5054
return $result;
5155
}
5256

57+
/**
58+
* Get class by reflection parameter
59+
*
60+
* @param ReflectionParameter $reflectionParameter
61+
* @return ReflectionClass|null
62+
* @throws ReflectionException
63+
*/
64+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
65+
{
66+
$parameterType = $reflectionParameter->getType();
67+
68+
return $parameterType && !$parameterType->isBuiltin()
69+
? new ReflectionClass($parameterType->getName())
70+
: null;
71+
}
72+
5373
/**
5474
* Get reflection parameter default value
5575
*
56-
* @param \ReflectionParameter $parameter
76+
* @param ReflectionParameter $parameter
5777
* @return array|mixed|null
5878
*/
59-
private function getReflectionParameterDefaultValue(\ReflectionParameter $parameter)
79+
private function getReflectionParameterDefaultValue(ReflectionParameter $parameter)
6080
{
6181
if ($parameter->isVariadic()) {
6282
return [];

0 commit comments

Comments
 (0)