mirror of
https://github.com/danog/psalm.git
synced 2024-11-29 20:28:59 +01:00
Add support for ignoredExceptions
This commit is contained in:
parent
e3ae1bf26f
commit
e1d922e9df
@ -5,6 +5,7 @@
|
||||
totallyTyped="true"
|
||||
strictBinaryOperands="false"
|
||||
rememberPropertyAssignmentsAfterCall="true"
|
||||
checkForThrowsDocblock="true"
|
||||
throwExceptionOnError="0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
@ -21,6 +22,12 @@
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
|
||||
<ignoreExceptions>
|
||||
<class name="UnexpectedValueException" />
|
||||
<class name="InvalidArgumentException" />
|
||||
<class name="LogicException" />
|
||||
</ignoreExceptions>
|
||||
|
||||
<issueHandlers>
|
||||
<MisplacedRequiredParam errorLevel="suppress" />
|
||||
<PossiblyNullOperand errorLevel="suppress" />
|
||||
@ -74,6 +81,8 @@
|
||||
</errorLevel>
|
||||
</PossiblyUnusedProperty>
|
||||
|
||||
<MissingThrowsDocblock errorLevel="info" />
|
||||
|
||||
<PossiblyUnusedMethod>
|
||||
<errorLevel type="suppress">
|
||||
<directory name="tests" />
|
||||
|
@ -622,9 +622,15 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
|
||||
if ($context->collect_exceptions) {
|
||||
if ($context->possibly_thrown_exceptions) {
|
||||
$ignored_exceptions = array_change_key_case($codebase->config->ignored_exceptions);
|
||||
|
||||
$undocumented_throws = array_diff_key($context->possibly_thrown_exceptions, $storage->throws);
|
||||
|
||||
foreach ($undocumented_throws as $possibly_thrown_exception => $_) {
|
||||
if (isset($ignored_exceptions[strtolower($possibly_thrown_exception)])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IssueBuffer::accepts(
|
||||
new MissingThrowsDocblock(
|
||||
$possibly_thrown_exception . ' is thrown but not caught - please either catch'
|
||||
|
@ -216,6 +216,11 @@ class Config
|
||||
*/
|
||||
public $check_for_throws_docblock = false;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
public $ignored_exceptions = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
@ -556,6 +561,13 @@ class Config
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($config_xml->ignoreExceptions) && isset($config_xml->ignoreExceptions->class)) {
|
||||
/** @var \SimpleXMLElement $exception_class */
|
||||
foreach ($config_xml->ignoreExceptions->class as $exception_class) {
|
||||
$config->ignored_exceptions[(string)$exception_class ['name']] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($config_xml->stubs) && isset($config_xml->stubs->file)) {
|
||||
/** @var \SimpleXMLElement $stub_file */
|
||||
foreach ($config_xml->stubs->file as $stub_file) {
|
||||
|
Loading…
Reference in New Issue
Block a user