Skip to content

Commit 54a44dc

Browse files
committed
MC-41712: Unable to perform any action in admin area with a customer.
1 parent a4071d4 commit 54a44dc

File tree

4 files changed

+98
-17
lines changed

4 files changed

+98
-17
lines changed

lib/internal/Magento/Framework/Reflection/Test/Unit/Fixture/TSample.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Framework\Reflection\Test\Unit\Fixture;
77

8-
class TSample implements TSampleInterface
8+
class TSample extends TSampleAbstract implements TSampleInterface
99
{
1010
/**
1111
* @inheritdoc
@@ -38,4 +38,12 @@ public function getOnlyNull()
3838
{
3939
return null;
4040
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function getDataOverridden()
46+
{
47+
return [];
48+
}
4149
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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\Reflection\Test\Unit\Fixture;
9+
10+
abstract class TSampleAbstract
11+
{
12+
/**
13+
* @return array
14+
*/
15+
public function getData()
16+
{
17+
return [];
18+
}
19+
20+
/**
21+
* @return array
22+
*/
23+
public function getDataOverridden()
24+
{
25+
return [];
26+
}
27+
}

lib/internal/Magento/Framework/Reflection/Test/Unit/TypeProcessorTest.php

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,50 @@ public function testGetOperationName()
330330

331331
/**
332332
* Checks a case when method has only `@inheritdoc` annotation.
333+
*
334+
* @dataProvider getReturnTypeWithInheritDocBlockDataProvider
335+
* @param string $methodName
336+
* @param array $returnTypeData
333337
*/
334-
public function testGetReturnTypeWithInheritDocBlock()
338+
public function testGetReturnTypeWithInheritDocBlock(string $methodName, array $returnTypeData)
335339
{
336-
$expected = [
337-
'type' => 'string',
338-
'isRequired' => true,
339-
'description' => null,
340-
'parameterCount' => 0
341-
];
342-
343340
$classReflection = new ClassReflection(TSample::class);
344-
$methodReflection = $classReflection->getMethod('getPropertyName');
341+
$methodReflection = $classReflection->getMethod($methodName);
345342

346-
self::assertEquals($expected, $this->typeProcessor->getGetterReturnType($methodReflection));
343+
self::assertEquals($returnTypeData, $this->typeProcessor->getGetterReturnType($methodReflection));
344+
}
345+
346+
public function getReturnTypeWithInheritDocBlockDataProvider(): array
347+
{
348+
return [
349+
[
350+
'getPropertyName',
351+
[
352+
'type' => 'string',
353+
'isRequired' => true,
354+
'description' => null,
355+
'parameterCount' => 0,
356+
],
357+
],
358+
[
359+
'getData',
360+
[
361+
'type' => 'array',
362+
'isRequired' => true,
363+
'description' => null,
364+
'parameterCount' => 0,
365+
],
366+
],
367+
[
368+
'getDataOverridden',
369+
[
370+
'type' => 'array',
371+
'isRequired' => true,
372+
'description' => null,
373+
'parameterCount' => 0,
374+
],
375+
],
376+
];
347377
}
348378

349379
/**

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -851,9 +851,11 @@ private function getMethodReturnAnnotation(MethodReflection $methodReflection)
851851
{
852852
$methodName = $methodReflection->getName();
853853
$returnAnnotations = $this->getReturnFromDocBlock($methodReflection);
854+
854855
if (empty($returnAnnotations)) {
856+
$classReflection = $methodReflection->getDeclaringClass();
855857
// method can inherit doc block from implemented interface, like for interceptors
856-
$implemented = $methodReflection->getDeclaringClass()->getInterfaces();
858+
$implemented = $classReflection->getInterfaces();
857859
/** @var ClassReflection $parentClassReflection */
858860
foreach ($implemented as $parentClassReflection) {
859861
if ($parentClassReflection->hasMethod($methodName)) {
@@ -863,14 +865,28 @@ private function getMethodReturnAnnotation(MethodReflection $methodReflection)
863865
break;
864866
}
865867
}
866-
// throw an exception if even implemented interface doesn't have return annotations
868+
867869
if (empty($returnAnnotations)) {
868-
throw new \InvalidArgumentException(
869-
"Method's return type must be specified using @return annotation. "
870-
. "See {$methodReflection->getDeclaringClass()->getName()}::{$methodName}()"
871-
);
870+
while ($classReflection->getParentClass()) {
871+
$classReflection = $classReflection->getParentClass();
872+
if ($classReflection->hasMethod($methodName)) {
873+
$returnAnnotations = $this->getReturnFromDocBlock(
874+
$classReflection->getMethod($methodName)
875+
);
876+
break;
877+
}
878+
}
879+
880+
// throw an exception if even implemented interface doesn't have return annotations
881+
if (empty($returnAnnotations)) {
882+
throw new \InvalidArgumentException(
883+
"Method's return type must be specified using @return annotation. "
884+
. "See {$methodReflection->getDeclaringClass()->getName()}::{$methodName}()"
885+
);
886+
}
872887
}
873888
}
889+
874890
return $returnAnnotations;
875891
}
876892

0 commit comments

Comments
 (0)