Skip to content

Commit fd980fe

Browse files
committed
AC-2841: Fixed SVC failure for Union Type
1 parent 6c73f31 commit fd980fe

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/Analyzer/ClassMethodAnalyzer.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
use Magento\SemanticVersionChecker\Operation\ExtendableClassConstructorOptionalParameterAdded;
2525
use Magento\SemanticVersionChecker\Operation\Visibility\MethodDecreased as VisibilityMethodDecreased;
2626
use Magento\SemanticVersionChecker\Operation\Visibility\MethodIncreased as VisibilityMethodIncreased;
27-
use PhpParser\Node\NullableType;
2827
use PhpParser\Node\Name;
28+
use PhpParser\Node\NullableType;
2929
use PhpParser\Node\Stmt\Class_;
3030
use PhpParser\Node\Stmt\ClassLike;
3131
use PhpParser\Node\Stmt\ClassMethod;
32+
use PhpParser\Node\UnionType;
3233
use PHPSemVerChecker\Comparator\Implementation;
3334
use PHPSemVerChecker\Operation\ClassMethodAdded;
3435
use PHPSemVerChecker\Operation\ClassMethodImplementationChanged;
@@ -410,12 +411,24 @@ private function isDeclarationReturnTypeChanged(ClassMethod $methodBefore, Class
410411
if (!$this->isReturnsEqualByNullability($methodBefore, $methodAfter)) {
411412
return true;
412413
}
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+
}
419432

420433
return $beforeMethodReturnType !== $afterMethodReturnType;
421434
}

0 commit comments

Comments
 (0)