Skip to content

Commit 478a69c

Browse files
committed
#31861: Code review changes
1 parent 9669403 commit 478a69c

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

dev/tests/static/framework/Magento/CodeMessDetector/Rule/Design/CookieAndSessionMisuse.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ private function isControllerPlugin(\ReflectionClass $class): bool
108108
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
109109
if (preg_match('/^(after|around|before).+/i', $method->getName())) {
110110
try {
111-
$parameter = $method->getParameters()[0];
112-
$argument = $this->getParameterClass($parameter);
111+
$argument = $this->getParameterClass($method->getParameters()[0]);
113112
} catch (\Throwable $exception) {
114113
//Non-existing class (autogenerated perhaps) or doesn't have an argument.
115114
continue;
@@ -138,8 +137,7 @@ private function isBlockPlugin(\ReflectionClass $class): bool
138137
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
139138
if (preg_match('/^(after|around|before).+/i', $method->getName())) {
140139
try {
141-
$parameter = $method->getParameters()[0];
142-
$argument = $this->getParameterClass($parameter);
140+
$argument = $this->getParameterClass($method->getParameters()[0]);
143141
} catch (\Throwable $exception) {
144142
//Non-existing class (autogenerated perhaps) or doesn't have an argument.
145143
continue;
@@ -169,14 +167,16 @@ private function doesUseRestrictedClasses(\ReflectionClass $class): bool
169167
if ($constructor) {
170168
foreach ($constructor->getParameters() as $argument) {
171169
try {
172-
if ($class = $this->getParameterClass($argument)) {
173-
if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class)
174-
|| $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class
175-
|| $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class)
176-
|| $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class
177-
) {
178-
return true;
179-
}
170+
$class = $this->getParameterClass($argument);
171+
if ($class === null) {
172+
continue;
173+
}
174+
if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class)
175+
|| $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class
176+
|| $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class)
177+
|| $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class
178+
) {
179+
return true;
180180
}
181181
} catch (\ReflectionException $exception) {
182182
//Failed to load the argument's class information

lib/internal/Magento/Framework/Code/Generator/EntityAbstract.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -326,24 +326,25 @@ protected function _getNullDefaultValue()
326326
private function extractParameterType(
327327
\ReflectionParameter $parameter
328328
): ?string {
329+
if (!$parameter->hasType()) {
330+
return null;
331+
}
332+
329333
/** @var string|null $typeName */
330334
$typeName = null;
331-
if ($parameter->hasType()) {
332-
if ($parameter->isArray()) {
333-
$typeName = 'array';
334-
} elseif ($parameterClass = $this->getParameterClass($parameter)) {
335-
$typeName = $this->_getFullyQualifiedClassName(
336-
$parameterClass->getName()
337-
);
338-
} elseif ($parameter->isCallable()) {
339-
$typeName = 'callable';
340-
} else {
341-
$typeName = $parameter->getType()->getName();
342-
}
343335

344-
if ($parameter->allowsNull()) {
345-
$typeName = '?' .$typeName;
346-
}
336+
if ($parameter->isArray()) {
337+
$typeName = 'array';
338+
} elseif ($parameterClass = $this->getParameterClass($parameter)) {
339+
$typeName = $this->_getFullyQualifiedClassName($parameterClass->getName());
340+
} elseif ($parameter->isCallable()) {
341+
$typeName = 'callable';
342+
} else {
343+
$typeName = $parameter->getType()->getName();
344+
}
345+
346+
if ($parameter->allowsNull()) {
347+
$typeName = '?' . $typeName;
347348
}
348349

349350
return $typeName;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ public function getConstructorArguments(\ReflectionClass $class, $groupByPositio
102102
*/
103103
private function processType(\ReflectionClass $class, \Laminas\Code\Reflection\ParameterReflection $parameter)
104104
{
105-
if ($parameterClass = $this->getParameterClass($parameter)) {
105+
$parameterClass = $this->getParameterClass($parameter);
106+
107+
if ($parameterClass) {
106108
return NamespaceResolver::NS_SEPARATOR . $parameterClass->getName();
107109
}
108110

109-
$type = $parameter->detectType();
111+
$type = $parameter->detectType();
110112

111113
if ($type === 'null') {
112114
return null;

0 commit comments

Comments
 (0)