Skip to content

Commit

Permalink
Fix PDOException::getCode return type
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Feb 14, 2022
1 parent 832a9a1 commit 64e7ed5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/Type/Php/ThrowableReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
continue 2;
}
}
if ($pdoException->isSuperTypeOf($classType)->yes()) {
$types[] = new StringType();
continue;
}

if (in_array(strtolower($class), [
'throwable',
'exception',
], true)) {
if (
$pdoException->isSuperTypeOf($classType)->yes()
|| in_array(strtolower($class), [
'throwable',
'exception',
'runtimeexception',
], true)
) {
$types[] = new BenevolentUnionType([new IntegerType(), new StringType()]);
continue;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/PHPStan/Analyser/data/bug-6001.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ public function doFoo(\Throwable $t): void
{
assertType('(int|string)', (new \Exception())->getCode());
assertType('(int|string)', $t->getCode());
assertType('int', (new \RuntimeException())->getCode());
assertType('string', (new \PDOException())->getCode());
assertType('int|string', (new \RuntimeException())->getCode());
assertType('int', (new \LogicException())->getCode());
assertType('int|string', (new \PDOException())->getCode());
assertType('int', (new MyException())->getCode());
assertType('string', (new SubPDOException())->getCode());
assertType('int|string', (new SubPDOException())->getCode());
assertType('1|2|3', (new ExceptionWithMethodTag())->getCode());
}

Expand Down

0 comments on commit 64e7ed5

Please sign in to comment.