|
24 | 24 | use Magento\SemanticVersionChecker\Operation\ExtendableClassConstructorOptionalParameterAdded;
|
25 | 25 | use Magento\SemanticVersionChecker\Operation\Visibility\MethodDecreased as VisibilityMethodDecreased;
|
26 | 26 | use Magento\SemanticVersionChecker\Operation\Visibility\MethodIncreased as VisibilityMethodIncreased;
|
27 |
| -use PhpParser\Node\NullableType; |
28 | 27 | use PhpParser\Node\Name;
|
| 28 | +use PhpParser\Node\NullableType; |
29 | 29 | use PhpParser\Node\Stmt\Class_;
|
30 | 30 | use PhpParser\Node\Stmt\ClassLike;
|
31 | 31 | use PhpParser\Node\Stmt\ClassMethod;
|
| 32 | +use PhpParser\Node\UnionType; |
32 | 33 | use PHPSemVerChecker\Comparator\Implementation;
|
33 | 34 | use PHPSemVerChecker\Operation\ClassMethodAdded;
|
34 | 35 | use PHPSemVerChecker\Operation\ClassMethodImplementationChanged;
|
@@ -410,12 +411,24 @@ private function isDeclarationReturnTypeChanged(ClassMethod $methodBefore, Class
|
410 | 411 | if (!$this->isReturnsEqualByNullability($methodBefore, $methodAfter)) {
|
411 | 412 | return true;
|
412 | 413 | }
|
413 |
| - $beforeMethodReturnType = $methodBefore->returnType instanceof NullableType |
414 |
| - ? (string) $methodBefore->returnType->type |
415 |
| - : (string) $methodBefore->returnType; |
416 |
| - $afterMethodReturnType = $methodAfter->returnType instanceof NullableType |
417 |
| - ? (string) $methodAfter->returnType->type |
418 |
| - : (string) $methodAfter->returnType; |
| 414 | + |
| 415 | + $methodBeforeReturnType = $methodBefore->returnType; |
| 416 | + if ($methodBeforeReturnType instanceof NullableType) { |
| 417 | + $beforeMethodReturnType = (string)$methodBeforeReturnType->type; |
| 418 | + } elseif ($methodBeforeReturnType instanceof UnionType) { |
| 419 | + $beforeMethodReturnType = implode('&', $methodBeforeReturnType->types); |
| 420 | + } else { |
| 421 | + $beforeMethodReturnType = (string)$methodBeforeReturnType; |
| 422 | + } |
| 423 | + |
| 424 | + $methodAfterReturnType = $methodAfter->returnType; |
| 425 | + if ($methodAfterReturnType instanceof NullableType) { |
| 426 | + $afterMethodReturnType = (string)$methodAfterReturnType->type; |
| 427 | + } elseif ($methodAfterReturnType instanceof UnionType) { |
| 428 | + $afterMethodReturnType = implode('&', $methodAfterReturnType->types); |
| 429 | + } else { |
| 430 | + $afterMethodReturnType = (string)$methodAfterReturnType; |
| 431 | + } |
419 | 432 |
|
420 | 433 | return $beforeMethodReturnType !== $afterMethodReturnType;
|
421 | 434 | }
|
|
0 commit comments