Skip to content

Commit 425eff7

Browse files
committed
Merge branch 'php8-develop' of github.com:magento-commerce/magento2ce into feature/32320-update-laminas-db
2 parents 53b6b54 + 21c3055 commit 425eff7

File tree

21 files changed

+717
-324
lines changed

21 files changed

+717
-324
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"laminas/laminas-crypt": "^3.4.0",
4242
"laminas/laminas-db": "^2.12.0",
4343
"laminas/laminas-dependency-plugin": "^2.1.0",
44-
"laminas/laminas-di": "^2.6.1",
44+
"laminas/laminas-di": "^3.2.0",
4545
"laminas/laminas-eventmanager": "^3.0.0",
4646
"laminas/laminas-feed": "^2.9.0",
4747
"laminas/laminas-form": "^2.10.0",
@@ -52,10 +52,11 @@
5252
"laminas/laminas-mail": "^2.9.0",
5353
"laminas/laminas-mime": "^2.5.0",
5454
"laminas/laminas-modulemanager": "^2.7",
55-
"laminas/laminas-mvc": "~2.7.0",
55+
"laminas/laminas-mvc": "^3.2.0",
56+
"laminas/laminas-mvc-console": "^1.3.0",
5657
"laminas/laminas-serializer": "^2.7.2",
5758
"laminas/laminas-server": "^2.6.1",
58-
"laminas/laminas-servicemanager": "^2.7.8",
59+
"laminas/laminas-servicemanager": "^3.6.0",
5960
"laminas/laminas-session": "^2.7.3",
6061
"laminas/laminas-soap": "^2.7.0",
6162
"laminas/laminas-stdlib": "^3.2.1",

composer.lock

Lines changed: 366 additions & 236 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
namespace Magento\CodeMessDetector\Rule\Design;
1010

11+
use Magento\Framework\Session\SessionManagerInterface;
12+
use Magento\Framework\Stdlib\Cookie\CookieReaderInterface;
1113
use PDepend\Source\AST\ASTClass;
1214
use PHPMD\AbstractNode;
1315
use PHPMD\AbstractRule;
1416
use PHPMD\Node\ClassNode;
1517
use PHPMD\Rule\ClassAware;
18+
use ReflectionClass;
19+
use ReflectionException;
20+
use ReflectionParameter;
1621

1722
/**
1823
* Session and Cookies must be used only in HTML Presentation layer.
@@ -105,7 +110,7 @@ private function isControllerPlugin(\ReflectionClass $class): bool
105110
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
106111
if (preg_match('/^(after|around|before).+/i', $method->getName())) {
107112
try {
108-
$argument = $method->getParameters()[0]->getClass();
113+
$argument = $this->getParameterClass($method->getParameters()[0]);
109114
} catch (\Throwable $exception) {
110115
//Non-existing class (autogenerated perhaps) or doesn't have an argument.
111116
continue;
@@ -134,7 +139,7 @@ private function isBlockPlugin(\ReflectionClass $class): bool
134139
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
135140
if (preg_match('/^(after|around|before).+/i', $method->getName())) {
136141
try {
137-
$argument = $method->getParameters()[0]->getClass();
142+
$argument = $this->getParameterClass($method->getParameters()[0]);
138143
} catch (\Throwable $exception) {
139144
//Non-existing class (autogenerated perhaps) or doesn't have an argument.
140145
continue;
@@ -164,14 +169,16 @@ private function doesUseRestrictedClasses(\ReflectionClass $class): bool
164169
if ($constructor) {
165170
foreach ($constructor->getParameters() as $argument) {
166171
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-
}
172+
$class = $this->getParameterClass($argument);
173+
if ($class === null) {
174+
continue;
175+
}
176+
if ($class->isSubclassOf(SessionManagerInterface::class)
177+
|| $class->getName() === SessionManagerInterface::class
178+
|| $class->isSubclassOf(CookieReaderInterface::class)
179+
|| $class->getName() === CookieReaderInterface::class
180+
) {
181+
return true;
175182
}
176183
} catch (\ReflectionException $exception) {
177184
//Failed to load the argument's class information
@@ -183,6 +190,22 @@ private function doesUseRestrictedClasses(\ReflectionClass $class): bool
183190
return false;
184191
}
185192

193+
/**
194+
* Get class by reflection parameter
195+
*
196+
* @param ReflectionParameter $reflectionParameter
197+
* @return ReflectionClass|null
198+
* @throws ReflectionException
199+
*/
200+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
201+
{
202+
$parameterType = $reflectionParameter->getType();
203+
204+
return $parameterType && !$parameterType->isBuiltin()
205+
? new ReflectionClass($parameterType->getName())
206+
: null;
207+
}
208+
186209
/**
187210
* @inheritdoc
188211
*

dev/tests/static/framework/Magento/TestFramework/Integrity/Library/Injectable.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Laminas\Code\Reflection\ClassReflection;
99
use Laminas\Code\Reflection\FileReflection;
1010
use Laminas\Code\Reflection\ParameterReflection;
11+
use ReflectionClass;
12+
use ReflectionException;
13+
use ReflectionParameter;
1114

1215
/**
1316
* Provide dependencies for the file
@@ -39,7 +42,7 @@ public function getDependencies(FileReflection $fileReflection)
3942
foreach ($method->getParameters() as $parameter) {
4043
try {
4144
/** @var ParameterReflection $parameter */
42-
$dependency = $parameter->getClass();
45+
$dependency = $this->getParameterClass($parameter);
4346
if ($dependency instanceof ClassReflection) {
4447
$this->dependencies[] = $dependency->getName();
4548
}
@@ -56,4 +59,20 @@ public function getDependencies(FileReflection $fileReflection)
5659

5760
return $this->dependencies;
5861
}
62+
63+
/**
64+
* Get class by reflection parameter
65+
*
66+
* @param ReflectionParameter $reflectionParameter
67+
* @return ReflectionClass|null
68+
* @throws ReflectionException
69+
*/
70+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
71+
{
72+
$parameterType = $reflectionParameter->getType();
73+
74+
return $parameterType && !$parameterType->isBuiltin()
75+
? new ReflectionClass($parameterType->getName())
76+
: null;
77+
}
5978
}

dev/tests/static/testsuite/Magento/Test/Integrity/PublicCodeTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\Test\Integrity;
77

88
use Magento\Framework\App\Utility\Files;
9+
use ReflectionClass;
10+
use ReflectionException;
11+
use ReflectionParameter;
912

1013
/**
1114
* Tests @api annotated code integrity
@@ -277,7 +280,7 @@ private function checkParameters($class, \ReflectionMethod $method, array $nonPu
277280
&& !$parameter->getType()->isBuiltin()
278281
&& !$this->isGenerated($parameter->getType()->getName())
279282
) {
280-
$parameterClass = $parameter->getClass();
283+
$parameterClass = $this->getParameterClass($parameter);
281284
/*
282285
* We don't want to check integrity of @api coverage of classes
283286
* that belong to different vendors, because it is too complicated.
@@ -286,7 +289,7 @@ private function checkParameters($class, \ReflectionMethod $method, array $nonPu
286289
* we don't want to fail test, because Zend is considered public by default,
287290
* and we don't care if Zend classes are @api-annotated
288291
*/
289-
if (!$parameterClass->isInternal()
292+
if ($parameterClass && !$parameterClass->isInternal()
290293
&& $this->areClassesFromSameVendor($parameterClass->getName(), $class)
291294
&& !$this->isPublished($parameterClass)
292295
) {
@@ -296,4 +299,20 @@ private function checkParameters($class, \ReflectionMethod $method, array $nonPu
296299
}
297300
return $nonPublishedClasses;
298301
}
302+
303+
/**
304+
* Get class by reflection parameter
305+
*
306+
* @param ReflectionParameter $reflectionParameter
307+
* @return ReflectionClass|null
308+
* @throws ReflectionException
309+
*/
310+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
311+
{
312+
$parameterType = $reflectionParameter->getType();
313+
314+
return $parameterType && !$parameterType->isBuiltin()
315+
? new ReflectionClass($parameterType->getName())
316+
: null;
317+
}
299318
}

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

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\Framework\Code\Generator;
77

88
use Laminas\Code\Generator\ValueGenerator;
9+
use ReflectionClass;
10+
use ReflectionException;
11+
use ReflectionParameter;
912

1013
/**
1114
* Abstract entity
@@ -323,29 +326,46 @@ protected function _getNullDefaultValue()
323326
private function extractParameterType(
324327
\ReflectionParameter $parameter
325328
): ?string {
329+
if (!$parameter->hasType()) {
330+
return null;
331+
}
332+
326333
/** @var string|null $typeName */
327334
$typeName = null;
328-
if ($parameter->hasType()) {
329-
if ($parameter->isArray()) {
330-
$typeName = 'array';
331-
} elseif ($parameter->getClass()) {
332-
$typeName = $this->_getFullyQualifiedClassName(
333-
$parameter->getClass()->getName()
334-
);
335-
} elseif ($parameter->isCallable()) {
336-
$typeName = 'callable';
337-
} else {
338-
$typeName = $parameter->getType()->getName();
339-
}
340335

341-
if ($parameter->allowsNull()) {
342-
$typeName = '?' .$typeName;
343-
}
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;
344348
}
345349

346350
return $typeName;
347351
}
348352

353+
/**
354+
* Get class by reflection parameter
355+
*
356+
* @param ReflectionParameter $reflectionParameter
357+
* @return ReflectionClass|null
358+
* @throws ReflectionException
359+
*/
360+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
361+
{
362+
$parameterType = $reflectionParameter->getType();
363+
364+
return $parameterType && !$parameterType->isBuiltin()
365+
? new ReflectionClass($parameterType->getName())
366+
: null;
367+
}
368+
349369
/**
350370
* Extract parameter default value
351371
*

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Magento\Framework\Code\Reader;
77

8+
use ReflectionClass;
9+
use ReflectionException;
10+
use ReflectionParameter;
11+
812
/**
913
* The class arguments reader
1014
*/
@@ -98,11 +102,13 @@ public function getConstructorArguments(\ReflectionClass $class, $groupByPositio
98102
*/
99103
private function processType(\ReflectionClass $class, \Laminas\Code\Reflection\ParameterReflection $parameter)
100104
{
101-
if ($parameter->getClass()) {
102-
return NamespaceResolver::NS_SEPARATOR . $parameter->getClass()->getName();
105+
$parameterClass = $this->getParameterClass($parameter);
106+
107+
if ($parameterClass) {
108+
return NamespaceResolver::NS_SEPARATOR . $parameterClass->getName();
103109
}
104110

105-
$type = $parameter->detectType();
111+
$type = $parameter->detectType();
106112

107113
if ($type === 'null') {
108114
return null;
@@ -121,6 +127,22 @@ private function processType(\ReflectionClass $class, \Laminas\Code\Reflection\P
121127
return $type;
122128
}
123129

130+
/**
131+
* Get class by reflection parameter
132+
*
133+
* @param ReflectionParameter $reflectionParameter
134+
* @return ReflectionClass|null
135+
* @throws ReflectionException
136+
*/
137+
private function getParameterClass(ReflectionParameter $reflectionParameter): ?ReflectionClass
138+
{
139+
$parameterType = $reflectionParameter->getType();
140+
141+
return $parameterType && !$parameterType->isBuiltin()
142+
? new ReflectionClass($parameterType->getName())
143+
: null;
144+
}
145+
124146
/**
125147
* Get arguments of parent __construct call
126148
*

0 commit comments

Comments
 (0)