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