diff --git a/resources/functionMap.php b/resources/functionMap.php index 57ab6c1bfc..526f62267b 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -2623,7 +2623,7 @@ 'Exception::__clone' => ['void'], 'Exception::__construct' => ['void', 'message='=>'string', 'code='=>'int', 'previous='=>'(?Throwable)|(?Exception)'], 'Exception::__toString' => ['string'], -'Exception::getCode' => ['mixed'], +'Exception::getCode' => ['int|string'], 'Exception::getFile' => ['string'], 'Exception::getLine' => ['int'], 'Exception::getMessage' => ['string'], @@ -12239,7 +12239,7 @@ 'Threaded::synchronized' => ['mixed', 'block'=>'Closure', '...args='=>'mixed'], 'Threaded::wait' => ['bool', 'timeout='=>'int'], 'Throwable::__toString' => ['string'], -'Throwable::getCode' => ['mixed'], +'Throwable::getCode' => ['int|string'], 'Throwable::getFile' => ['string'], 'Throwable::getLine' => ['int'], 'Throwable::getMessage' => ['string'], diff --git a/stubs/Exception.stub b/stubs/Exception.stub index e95c24b250..25fb0699a6 100644 --- a/stubs/Exception.stub +++ b/stubs/Exception.stub @@ -9,7 +9,7 @@ interface Throwable public function getMessage(); /** - * @return mixed + * @return int|string * @throws void */ public function getCode(); @@ -60,7 +60,7 @@ class Exception implements Throwable final public function getMessage(): string {} /** - * @return mixed + * @return int|string * @throws void */ final public function getCode() {} @@ -107,7 +107,7 @@ class Error implements Throwable final public function getMessage(): string {} /** - * @return mixed + * @return int|string * @throws void */ final public function getCode() {} diff --git a/tests/PHPStan/Analyser/data/generics.php b/tests/PHPStan/Analyser/data/generics.php index 032fa71f17..5489413820 100644 --- a/tests/PHPStan/Analyser/data/generics.php +++ b/tests/PHPStan/Analyser/data/generics.php @@ -1400,7 +1400,7 @@ public function process($class): void { } function (\Throwable $e): void { - assertType('mixed', $e->getCode()); + assertType('int|string', $e->getCode()); }; function (): void {