Skip to content

Commit 9f92a45

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-95945: Add a code mess rule for improper session and cookies usages
1 parent b7a8be5 commit 9f92a45

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ private function isControllerPlugin(\ReflectionClass $class): bool
7777
try {
7878
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
7979
if (preg_match('/^(after|around|before).+/i', $method->getName())) {
80-
$argument = $method->getParameters()[0]->getClass();
80+
try {
81+
$argument = $method->getParameters()[0]->getClass();
82+
} catch (\ReflectionException $exception) {
83+
//Non-existing class (autogenerated perhaps)
84+
continue;
85+
}
8186
$isAction = $argument->isSubclassOf(\Magento\Framework\App\ActionInterface::class)
8287
|| $argument->getName() === \Magento\Framework\App\ActionInterface::class;
8388
if ($isAction) {
@@ -101,7 +106,12 @@ private function isBlockPlugin(\ReflectionClass $class): bool
101106
try {
102107
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
103108
if (preg_match('/^(after|around|before).+/i', $method->getName())) {
104-
$argument = $method->getParameters()[0]->getClass();
109+
try {
110+
$argument = $method->getParameters()[0]->getClass();
111+
} catch (\ReflectionException $exception) {
112+
//Non-existing class (autogenerated perhaps)
113+
continue;
114+
}
105115
$isBlock = $argument->isSubclassOf(\Magento\Framework\View\Element\BlockInterface::class)
106116
|| $argument->getName() === \Magento\Framework\View\Element\BlockInterface::class;
107117
if ($isBlock) {
@@ -125,14 +135,19 @@ private function doesUseRestrictedClasses(\ReflectionClass $class): bool
125135
$constructor = $class->getConstructor();
126136
if ($constructor) {
127137
foreach ($constructor->getParameters() as $argument) {
128-
if ($class = $argument->getClass()) {
129-
if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class)
130-
|| $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class
131-
|| $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class)
132-
|| $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class
133-
) {
134-
return true;
138+
try {
139+
if ($class = $argument->getClass()) {
140+
if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class)
141+
|| $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class
142+
|| $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class)
143+
|| $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class
144+
) {
145+
return true;
146+
}
135147
}
148+
} catch (\ReflectionException $exception) {
149+
//Failed to load the argument's class information
150+
continue;
136151
}
137152
}
138153
}

0 commit comments

Comments
 (0)