Skip to content

Commit

Permalink
#31861: Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaschenko committed Mar 2, 2021
1 parent 9669403 commit 478a69c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
31 changes: 16 additions & 15 deletions lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 478a69c

Please sign in to comment.