Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Exception->getCode return type provider #7525

Merged
merged 3 commits into from Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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