diff --git a/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/CookieAndSessionMisuse.php b/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/CookieAndSessionMisuse.php index 5c9712cac879d..17a93add899f2 100644 --- a/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/CookieAndSessionMisuse.php +++ b/dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/CookieAndSessionMisuse.php @@ -108,8 +108,7 @@ private function isControllerPlugin(\ReflectionClass $class): bool foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { if (preg_match('/^(after|around|before).+/i', $method->getName())) { try { - $parameter = $method->getParameters()[0]; - $argument = $this->getParameterClass($parameter); + $argument = $this->getParameterClass($method->getParameters()[0]); } catch (\Throwable $exception) { //Non-existing class (autogenerated perhaps) or doesn't have an argument. continue; @@ -138,8 +137,7 @@ private function isBlockPlugin(\ReflectionClass $class): bool foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { if (preg_match('/^(after|around|before).+/i', $method->getName())) { try { - $parameter = $method->getParameters()[0]; - $argument = $this->getParameterClass($parameter); + $argument = $this->getParameterClass($method->getParameters()[0]); } catch (\Throwable $exception) { //Non-existing class (autogenerated perhaps) or doesn't have an argument. continue; @@ -169,14 +167,16 @@ private function doesUseRestrictedClasses(\ReflectionClass $class): bool if ($constructor) { foreach ($constructor->getParameters() as $argument) { try { - if ($class = $this->getParameterClass($argument)) { - if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class) - || $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class - || $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class) - || $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class - ) { - return true; - } + $class = $this->getParameterClass($argument); + if ($class === null) { + continue; + } + if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class) + || $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class + || $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class) + || $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class + ) { + return true; } } catch (\ReflectionException $exception) { //Failed to load the argument's class information diff --git a/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php b/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php index 11c1aae92b5f5..b0fe493ab0eaa 100644 --- a/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php +++ b/lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php @@ -326,24 +326,25 @@ protected function _getNullDefaultValue() private function extractParameterType( \ReflectionParameter $parameter ): ?string { + if (!$parameter->hasType()) { + return null; + } + /** @var string|null $typeName */ $typeName = null; - if ($parameter->hasType()) { - if ($parameter->isArray()) { - $typeName = 'array'; - } elseif ($parameterClass = $this->getParameterClass($parameter)) { - $typeName = $this->_getFullyQualifiedClassName( - $parameterClass->getName() - ); - } elseif ($parameter->isCallable()) { - $typeName = 'callable'; - } else { - $typeName = $parameter->getType()->getName(); - } - if ($parameter->allowsNull()) { - $typeName = '?' .$typeName; - } + if ($parameter->isArray()) { + $typeName = 'array'; + } elseif ($parameterClass = $this->getParameterClass($parameter)) { + $typeName = $this->_getFullyQualifiedClassName($parameterClass->getName()); + } elseif ($parameter->isCallable()) { + $typeName = 'callable'; + } else { + $typeName = $parameter->getType()->getName(); + } + + if ($parameter->allowsNull()) { + $typeName = '?' . $typeName; } return $typeName; diff --git a/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php b/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php index a49aa7efaaa07..3396093c78bc4 100644 --- a/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php +++ b/lib/internal/Magento/Framework/Code/Reader/ArgumentsReader.php @@ -102,11 +102,13 @@ public function getConstructorArguments(\ReflectionClass $class, $groupByPositio */ private function processType(\ReflectionClass $class, \Laminas\Code\Reflection\ParameterReflection $parameter) { - if ($parameterClass = $this->getParameterClass($parameter)) { + $parameterClass = $this->getParameterClass($parameter); + + if ($parameterClass) { return NamespaceResolver::NS_SEPARATOR . $parameterClass->getName(); } - $type = $parameter->detectType(); + $type = $parameter->detectType(); if ($type === 'null') { return null;