Skip to content

Commit f84c7aa

Browse files
committed
AC-6437:Ensure PHP8.1 Support after 7.4 removal
- Created Trait GetReflectionMethodReturnTypeValueTrait.php for getting return type value of Reflection Method - Fixed static and unit test failures
1 parent bfaa677 commit f84c7aa

File tree

10 files changed

+84
-101
lines changed

10 files changed

+84
-101
lines changed

app/code/Magento/Deploy/Service/DeployStaticFile.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public function __construct(
8282
}
8383

8484
/**
85+
* Deploy static file
86+
*
8587
* @param string $fileName
8688
* @param array $params ['area' =>, 'theme' =>, 'locale' =>, 'module' =>]
8789
* @return string
@@ -98,6 +100,8 @@ public function deployFile(string $fileName, array $params = []): string
98100
}
99101

100102
/**
103+
* Delete static file
104+
*
101105
* @param string $path
102106
* @return void
103107
* @throws FileSystemException
@@ -138,6 +142,8 @@ public function readFile(string $fileName, string $filePath): bool|string
138142
}
139143

140144
/**
145+
* Open static file
146+
*
141147
* @param string $fileName
142148
* @param string $filePath
143149
* @return WriteInterface

app/code/Magento/Deploy/Test/Unit/Service/DeployTranslationsDictionaryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ function ($checkDictionary, $params) use ($dictionary, $area, $theme, $locale) {
7676
$this->assertEquals($area, $params['area']);
7777
$this->assertEquals($theme, $params['theme']);
7878
$this->assertEquals($locale, $params['locale']);
79+
80+
return $dictionary;
7981
}
8082
);
8183

lib/internal/Magento/Framework/Async/Code/Generator/ProxyDeferredGenerator.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\Async\DeferredInterface;
1111
use Magento\Framework\Code\Generator\EntityAbstract;
12+
use Magento\Framework\GetReflectionMethodReturnTypeValueTrait;
1213
use Magento\Framework\ObjectManager\DefinitionFactory;
1314
use Magento\Framework\ObjectManager\NoninterceptableInterface;
1415

@@ -17,6 +18,8 @@
1718
*/
1819
class ProxyDeferredGenerator extends EntityAbstract
1920
{
21+
use GetReflectionMethodReturnTypeValueTrait;
22+
2023
/**
2124
* Entity type
2225
*/
@@ -234,34 +237,4 @@ protected function _validateData()
234237

235238
return $result;
236239
}
237-
238-
/**
239-
* Returns return type
240-
*
241-
* @param \ReflectionMethod $method
242-
* @return null|string
243-
*/
244-
private function getReturnTypeValue(\ReflectionMethod $method): ?string
245-
{
246-
$returnTypeValue = null;
247-
$returnType = $method->getReturnType();
248-
if ($returnType) {
249-
if ($returnType instanceof \ReflectionUnionType) {
250-
$returnTypeValue = [];
251-
foreach ($method->getReturnType()->getTypes() as $type) {
252-
$returnTypeValue[] = $type->getName();
253-
}
254-
255-
$returnTypeValue = implode('|', $returnTypeValue);
256-
257-
} else {
258-
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
259-
$returnTypeValue .= ($returnType->getName() === 'self')
260-
? $this->_getFullyQualifiedClassName($method->getDeclaringClass()->getName())
261-
: $returnType->getName();
262-
}
263-
}
264-
265-
return $returnTypeValue;
266-
}
267240
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework;
9+
10+
/**
11+
* Returns the return type of reflection method
12+
*/
13+
trait GetReflectionMethodReturnTypeValueTrait
14+
{
15+
/**
16+
* Returns return type
17+
*
18+
* @param \ReflectionMethod $method
19+
* @return string|null
20+
*/
21+
private function getReturnTypeValue(\ReflectionMethod $method): ?string
22+
{
23+
$returnTypeValue = null;
24+
$returnType = $method->getReturnType();
25+
if ($returnType) {
26+
if ($returnType instanceof \ReflectionUnionType) {
27+
$returnTypeValue = [];
28+
foreach ($method->getReturnType()->getTypes() as $type) {
29+
$returnTypeValue[] = $type->getName();
30+
}
31+
32+
$returnTypeValue = implode('|', $returnTypeValue);
33+
} else {
34+
$className = $method->getDeclaringClass()->getName();
35+
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
36+
$returnTypeValue .= ($returnType->getName() === 'self')
37+
? $className ? '\\' . ltrim($className, '\\') : ''
38+
: $returnType->getName();
39+
}
40+
}
41+
42+
return $returnTypeValue;
43+
}
44+
}

lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
namespace Magento\Framework\Interception\Code\Generator;
99

1010
use Magento\Framework\Code\Generator\EntityAbstract;
11+
use Magento\Framework\GetReflectionMethodReturnTypeValueTrait;
1112

1213
class Interceptor extends EntityAbstract
1314
{
15+
use GetReflectionMethodReturnTypeValueTrait;
16+
1417
public const ENTITY_TYPE = 'interceptor';
1518

1619
/**
@@ -200,35 +203,4 @@ protected function _validateData()
200203

201204
return $result;
202205
}
203-
204-
/**
205-
* Returns return type
206-
*
207-
* @param \ReflectionMethod $method
208-
* @return null|string
209-
*/
210-
private function getReturnTypeValue(\ReflectionMethod $method): ?string
211-
{
212-
$returnTypeValue = null;
213-
$returnType = $method->getReturnType();
214-
if ($returnType) {
215-
216-
if ($returnType instanceof \ReflectionUnionType) {
217-
$returnTypeValue = [];
218-
foreach ($method->getReturnType()->getTypes() as $type) {
219-
$returnTypeValue[] = $type->getName();
220-
}
221-
222-
$returnTypeValue = implode('|', $returnTypeValue);
223-
224-
} else {
225-
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
226-
$returnTypeValue .= ($returnType->getName() === 'self')
227-
? $this->_getFullyQualifiedClassName($method->getDeclaringClass()->getName())
228-
: $returnType->getName();
229-
}
230-
}
231-
232-
return $returnTypeValue;
233-
}
234206
}

lib/internal/Magento/Framework/Interception/Test/Unit/Code/Generator/_files/ReflectionUnionTypeSample.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
class ReflectionUnionTypeSample
1111
{
12+
/**
13+
* @var int|string
14+
*/
1215
private int|string $attribute;
1316

1417
public function getValue(): int|string

lib/internal/Magento/Framework/MessageQueue/Code/Generator/RemoteServiceGenerator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
class RemoteServiceGenerator extends \Magento\Framework\Code\Generator\EntityAbstract
2222
{
23-
const ENTITY_TYPE = 'remote';
24-
const REMOTE_SERVICE_SUFFIX = 'Remote';
23+
public const ENTITY_TYPE = 'remote';
24+
public const REMOTE_SERVICE_SUFFIX = 'Remote';
2525

2626
/**
2727
* @var CommunicationConfig
@@ -241,6 +241,7 @@ protected function validateResultClassName()
241241
* @return ReflectionGenerator
242242
*
243243
* @deprecated 103.0.0
244+
* @see https://jira.corp.adobe.com/browse/MAGETWO-56305
244245
*/
245246
private function getReflectionGenerator()
246247
{

lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace Magento\Framework\ObjectManager\Code\Generator;
99

10+
use Magento\Framework\GetReflectionMethodReturnTypeValueTrait;
11+
1012
class Proxy extends \Magento\Framework\Code\Generator\EntityAbstract
1113
{
14+
use GetReflectionMethodReturnTypeValueTrait;
15+
1216
/**
1317
* Entity type
1418
*/
@@ -268,34 +272,4 @@ protected function _validateData()
268272

269273
return $result;
270274
}
271-
272-
/**
273-
* Returns return type
274-
*
275-
* @param \ReflectionMethod $method
276-
* @return null|string
277-
*/
278-
private function getReturnTypeValue(\ReflectionMethod $method): ?string
279-
{
280-
$returnTypeValue = null;
281-
$returnType = $method->getReturnType();
282-
if ($returnType) {
283-
if ($returnType instanceof \ReflectionUnionType) {
284-
$returnTypeValue = [];
285-
foreach ($method->getReturnType()->getTypes() as $type) {
286-
$returnTypeValue[] = $type->getName();
287-
}
288-
289-
$returnTypeValue = implode('|', $returnTypeValue);
290-
291-
} else {
292-
$returnTypeValue = ($returnType->allowsNull() && $returnType->getName() !== 'mixed' ? '?' : '');
293-
$returnTypeValue .= ($returnType->getName() === 'self')
294-
? $this->_getFullyQualifiedClassName($method->getDeclaringClass()->getName())
295-
: $returnType->getName();
296-
}
297-
}
298-
299-
return $returnTypeValue;
300-
}
301275
}

lib/internal/Magento/Framework/ObjectManager/Code/Generator/Repository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
* Class Repository
1919
* @deprecated 101.0.0 As current implementation breaks Repository contract. Not removed from codebase to prevent
2020
* possible backward incompatibilities if this functionality being used by 3rd party developers.
21+
* @see https://jira.corp.adobe.com/browse/MAGETWO-70985
2122
*/
2223
class Repository extends \Magento\Framework\Code\Generator\EntityAbstract
2324
{
2425
/**
2526
* Entity type repository
2627
*/
27-
const ENTITY_TYPE = 'repository';
28+
public const ENTITY_TYPE = 'repository';
2829

2930
/**
3031
* The namespace of repository interface

lib/internal/Magento/Framework/Reflection/TypeProcessor.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class TypeProcessor
5959
*
6060
* @return NameFinder
6161
*
62-
* @deprecated 100.1.0
62+
* @deprecated 100.1.0 Refactor TypeProcessor
63+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
6364
*/
6465
private function getNameFinder()
6566
{
@@ -254,7 +255,8 @@ public function getDescription(DocBlockReflection $doc)
254255
* @param string $getterName
255256
* @return string
256257
*
257-
* @deprecated 100.1.0
258+
* @deprecated 100.1.0 Refactor TypeProcessor
259+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
258260
*/
259261
public function dataObjectGetterNameToFieldName($getterName)
260262
{
@@ -267,7 +269,8 @@ public function dataObjectGetterNameToFieldName($getterName)
267269
* @param string $shortDescription
268270
* @return string
269271
*
270-
* @deprecated 100.1.0
272+
* @deprecated 100.1.0 Refactor TypeProcessor
273+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
271274
*/
272275
protected function dataObjectGetterDescriptionToFieldDescription($shortDescription)
273276
{
@@ -701,7 +704,8 @@ public function getParamDescription(ParameterReflection $param)
701704
* @return string processed method name
702705
* @throws \Exception If $camelCaseProperty has no corresponding getter method
703706
*
704-
* @deprecated 100.1.0
707+
* @deprecated 100.1.0 Refactor TypeProcessor
708+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
705709
*/
706710
public function findGetterMethodName(ClassReflection $class, $camelCaseProperty)
707711
{
@@ -739,7 +743,8 @@ protected function setType(&$value, $type)
739743
* @return string processed method name
740744
* @throws \Exception If $camelCaseProperty has no corresponding setter method
741745
*
742-
* @deprecated 100.1.0
746+
* @deprecated 100.1.0 Refactor TypeProcessor
747+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
743748
*/
744749
public function findSetterMethodName(ClassReflection $class, $camelCaseProperty)
745750
{
@@ -756,7 +761,8 @@ public function findSetterMethodName(ClassReflection $class, $camelCaseProperty)
756761
* @return string processed method name
757762
* @throws \Exception If $camelCaseProperty has no corresponding setter method
758763
*
759-
* @deprecated 100.1.0
764+
* @deprecated 100.1.0 Refactor TypeProcessor
765+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
760766
*/
761767
protected function findAccessorMethodName(
762768
ClassReflection $class,
@@ -777,7 +783,8 @@ protected function findAccessorMethodName(
777783
* @param string $methodName
778784
* @return bool
779785
*
780-
* @deprecated 100.1.0
786+
* @deprecated 100.1.0 Refactor TypeProcessor
787+
* @see https://jira.corp.adobe.com/browse/MAGETWO-51906
781788
*/
782789
protected function classHasMethod(ClassReflection $class, $methodName)
783790
{

0 commit comments

Comments
 (0)