Skip to content

Commit 14a0449

Browse files
committed
PHP 8.1 compatibility
1 parent 561f5b6 commit 14a0449

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* @author The S Group <[email protected]>
4+
* @copyright 2022 Sashas IT Support Inc. (https://www.sashas.org)
5+
* @license http://opensource.org/licenses/GPL-3.0 GNU General Public License, version 3 (GPL-3.0)
6+
*/
7+
8+
namespace Magento\TestFramework;
9+
10+
use ReflectionClass;
11+
use ReflectionParameter;
12+
13+
/**
14+
* Returns a reflection parameter's class if possible.
15+
*/
16+
trait GetParameterClassTrait
17+
{
18+
/**
19+
* Get class by reflection parameter
20+
*
21+
* @param ReflectionParameter $reflectionParameter
22+
*
23+
* @return ReflectionClass|null
24+
* @throws ReflectionException
25+
*/
26+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
27+
{
28+
$parameterType = $reflectionParameter->getType();
29+
// In PHP8, $parameterType could be an instance of ReflectionUnionType, which doesn't have isBuiltin method.
30+
if ($parameterType !== null && method_exists($parameterType, 'isBuiltin') === false) {
31+
return null;
32+
}
33+
34+
return $parameterType && !$parameterType->isBuiltin()
35+
? new ReflectionClass($parameterType->getName())
36+
: null;
37+
}
38+
}

static/integrity/testsuite/Magento/Test/Integrity/Di/CompilerTest.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ protected function pluginDataProvider()
412412
$plugin = $node->attributes->getNamedItem('type')->nodeValue;
413413
if (!in_array($plugin, $this->getPluginBlacklist())) {
414414
$plugin = \Magento\Framework\App\Utility\Classes::resolveVirtualType($plugin);
415-
$plugins[] = ['plugin' => $plugin, 'intercepted type' => $type];
415+
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
416+
$plugins[] = ['plugin' => $plugin, 'intercepted type' => $type];
417+
} else {
418+
$plugins[] = [$plugin, $type];
419+
}
420+
416421
}
417422
}
418423
}

static/phpmd/framework/Magento/CodeMessDetector/Rule/Design/CookieAndSessionMisuse.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313
use PHPMD\AbstractRule;
1414
use PHPMD\Node\ClassNode;
1515
use PHPMD\Rule\ClassAware;
16-
16+
use Magento\TestFramework\GetParameterClassTrait;
1717
/**
1818
* Session and Cookies must be used only in HTML Presentation layer.
1919
*
2020
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2121
*/
2222
class CookieAndSessionMisuse extends AbstractRule implements ClassAware
2323
{
24+
use GetParameterClassTrait;
25+
2426
/**
2527
* Is given class a controller?
2628
*
@@ -164,15 +166,18 @@ private function doesUseRestrictedClasses(\ReflectionClass $class): bool
164166
if ($constructor) {
165167
foreach ($constructor->getParameters() as $argument) {
166168
try {
167-
if ($class = $argument->getClass()) {
168-
if ($class->isSubclassOf(\Magento\Framework\Session\SessionManagerInterface::class)
169-
|| $class->getName() === \Magento\Framework\Session\SessionManagerInterface::class
170-
|| $class->isSubclassOf(\Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class)
171-
|| $class->getName() === \Magento\Framework\Stdlib\Cookie\CookieReaderInterface::class
172-
) {
173-
return true;
174-
}
169+
$class = $this->getParameterClass($argument);
170+
if ($class === null) {
171+
continue;
175172
}
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+
}
180+
176181
} catch (\ReflectionException $exception) {
177182
//Failed to load the argument's class information
178183
continue;

unit/framework/bootstrap.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ function ($errNo, $errStr, $errFile, $errLine) {
5151
];
5252

5353
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
54-
54+
//PHP 8.1 compatibility
55+
if ($errStr == 'auto_detect_line_endings is deprecated') {
56+
return;
57+
}
5558
throw new \PHPUnit\Framework\Exception(
5659
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
5760
$errNo

0 commit comments

Comments
 (0)