Skip to content

Commit

Permalink
new ReflectionClass() can throw ReflectionException
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 2, 2021
1 parent b5e4bf0 commit 00d3ef4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ private function createMethod(
);
$stubPhpDocParameterVariadicity[$name] = $paramTag->isVariadic();
}

$throwsTag = $stubPhpDoc->getThrowsTag();
if ($throwsTag !== null) {
$throwType = $throwsTag->getType();
}
}
}
if ($stubPhpDocPair === null && $reflectionMethod !== null && $reflectionMethod->getDocComment() !== false) {
Expand Down
1 change: 1 addition & 0 deletions stubs/ReflectionClass.stub
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ReflectionClass

/**
* @param T|class-string<T> $argument
* @throws ReflectionException
*/
public function __construct($argument) {}

Expand Down
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Exceptions/data/too-wide-throws-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,14 @@ public function doFoo(): void
}

}

class ThrowsReflectionException
{

/** @throws \ReflectionException */
public function doFoo(string $s): void
{
new \ReflectionClass($s);
}

}

0 comments on commit 00d3ef4

Please sign in to comment.