Skip to content

Commit

Permalink
Use BenevolentUnion
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Feb 23, 2022
1 parent 0c68467 commit 6acfaff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Type/Php/ThrowableReturnTypeExtension.php
Expand Up @@ -14,7 +14,6 @@
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\UnionType;
use Throwable;
use function count;
use function in_array;
Expand Down Expand Up @@ -53,7 +52,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
}

if ($pdoException->isSuperTypeOf($classType)->yes()) {
$types[] = new UnionType([new IntegerType(), new StringType()]);
$types[] = new BenevolentUnionType([new IntegerType(), new StringType()]);
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/data/bug-6001.php
Expand Up @@ -13,9 +13,9 @@ public function doFoo(\Throwable $t): void
assertType('(int|string)', $t->getCode());
assertType('(int|string)', (new \RuntimeException())->getCode());
assertType('int', (new \LogicException())->getCode());
assertType('int|string', (new \PDOException())->getCode());
assertType('(int|string)', (new \PDOException())->getCode());
assertType('int', (new MyException())->getCode());
assertType('int|string', (new SubPDOException())->getCode());
assertType('(int|string)', (new SubPDOException())->getCode());
assertType('1|2|3', (new ExceptionWithMethodTag())->getCode());
}

Expand All @@ -25,7 +25,7 @@ public function doFoo(\Throwable $t): void
*/
public function doBar($exception): void
{
assertType('int|string', $exception->getCode());
assertType('(int|string)', $exception->getCode());
}

}
Expand Down

0 comments on commit 6acfaff

Please sign in to comment.