Skip to content

Commit

Permalink
Merge pull request #7525 from VincentLanglet/exceptionCode2
Browse files Browse the repository at this point in the history
Fix for Exception->getCode return type provider
  • Loading branch information
orklah committed Jan 30, 2022
2 parents b45306c + 854a341 commit 286176f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Expand Up @@ -97,7 +97,11 @@ public static function fetch(

if ($premixin_method_id->method_name === 'getcode'
&& $premixin_method_id->fq_class_name !== Exception::class
&& in_array(Throwable::class, $class_storage->class_implements)) {
&& (
$codebase->classImplements($premixin_method_id->fq_class_name, Throwable::class)
|| $codebase->interfaceExtends($premixin_method_id->fq_class_name, Throwable::class)
)
) {
if ($premixin_method_id->fq_class_name === PDOException::class) {
return Type::getString();
} else {
Expand Down
13 changes: 11 additions & 2 deletions tests/ReturnTypeProvider/ExceptionCodeTest.php
Expand Up @@ -35,14 +35,23 @@ function f(\PDOException $e): string {
',
[],
];
yield 'Exception' => [
yield 'CustomThrowable' => [
'<?php
interface CustomThrowable extends \Throwable {}
/** @var CustomThrowable $e */
$code = $e->getCode();
',
['$code' => 'int'],
];
yield 'Throwable' => [
'<?php
/** @var \Throwable $e */
$code = $e->getCode();
',
['$code' => 'int|string'],
];
yield 'Throwable' => [
yield 'Exception' => [
'<?php
/** @var \Exception $e */
$code = $e->getCode();
Expand Down

0 comments on commit 286176f

Please sign in to comment.