Skip to content

Commit

Permalink
Merge branch '4.x' into upstream-master
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Jan 30, 2022
2 parents 31941d1 + 4729eb0 commit a2977a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Expand Up @@ -100,7 +100,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
Expand Up @@ -19,7 +19,7 @@ final class AfterFunctionLikeAnalysisEvent
/**
* @var FunctionLikeStorage
*/
private $classlike_storage;
private $functionlike_storage;
/**
* @var StatementsSource
*/
Expand Down Expand Up @@ -49,15 +49,15 @@ final class AfterFunctionLikeAnalysisEvent
*/
public function __construct(
Node\FunctionLike $stmt,
FunctionLikeStorage $classlike_storage,
FunctionLikeStorage $functionlike_storage,
StatementsSource $statements_source,
Codebase $codebase,
array $file_replacements,
NodeTypeProvider $node_type_provider,
Context $context
) {
$this->stmt = $stmt;
$this->classlike_storage = $classlike_storage;
$this->functionlike_storage = $functionlike_storage;
$this->statements_source = $statements_source;
$this->codebase = $codebase;
$this->file_replacements = $file_replacements;
Expand All @@ -70,9 +70,17 @@ public function getStmt(): Node\FunctionLike
return $this->stmt;
}

/**
* @deprecated Will be removed in Psalm v5.0, use getFunctionlikeStorage() instead
*/
public function getClasslikeStorage(): FunctionLikeStorage
{
return $this->classlike_storage;
return $this->functionlike_storage;
}

public function getFunctionlikeStorage(): FunctionLikeStorage
{
return $this->functionlike_storage;
}

public function getStatementsSource(): StatementsSource
Expand Down
17 changes: 13 additions & 4 deletions tests/ReturnTypeProvider/ExceptionCodeTest.php
Expand Up @@ -38,15 +38,24 @@ function f(\PDOException $e): string {
',
'assertions' => [],
];
yield 'Exception' => [
'code' => '<?php
yield 'CustomThrowable' => [
'<?php
interface CustomThrowable extends \Throwable {}
/** @var CustomThrowable $e */
$code = $e->getCode();
',
['$code' => 'int'],
];
yield 'Throwable' => [
'<?php
/** @var \Throwable $e */
$code = $e->getCode();
',
'assertions' => ['$code' => 'int|string'],
];
yield 'Throwable' => [
'code' => '<?php
yield 'Exception' => [
'<?php
/** @var \Exception $e */
$code = $e->getCode();
',
Expand Down

0 comments on commit a2977a5

Please sign in to comment.