diff --git a/config.xsd b/config.xsd index 8dd9c5d1a..c8075b423 100644 --- a/config.xsd +++ b/config.xsd @@ -146,6 +146,7 @@ + diff --git a/docs/issues.md b/docs/issues.md index 6997ffdd1..a07557ad6 100644 --- a/docs/issues.md +++ b/docs/issues.md @@ -700,6 +700,19 @@ class A { } ``` +### MissingDependency + +Emitted when referencing a class that doesn’t exist + +```php +/** + * @psalm-suppress UndefinedClass + */ +class A extends B {} + +$a = new A(); +``` + ### MissingDocblockType Emitted when a docblock is present, but the type is missing or badly formatted diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index eef83303f..7d11712f9 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -10,6 +10,7 @@ use Psalm\FileManipulation\FileManipulationBuffer; use Psalm\Issue\DuplicateClass; use Psalm\Issue\InaccessibleProperty; use Psalm\Issue\InvalidClass; +use Psalm\Issue\MissingDependency; use Psalm\Issue\ReservedWord; use Psalm\Issue\UndefinedClass; use Psalm\IssueBuffer; @@ -271,7 +272,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc foreach ($class_storage->invalid_dependencies as $dependency_class_name) { if (IssueBuffer::accepts( - new UndefinedClass( + new MissingDependency( $fq_class_name . ' depends on class or interface ' . $dependency_class_name . ' that does not exist', $code_location diff --git a/src/Psalm/Checker/Statements/Expression/Fetch/ArrayFetchChecker.php b/src/Psalm/Checker/Statements/Expression/Fetch/ArrayFetchChecker.php index 5f19af1e3..13e402359 100644 --- a/src/Psalm/Checker/Statements/Expression/Fetch/ArrayFetchChecker.php +++ b/src/Psalm/Checker/Statements/Expression/Fetch/ArrayFetchChecker.php @@ -84,6 +84,7 @@ class ArrayFetchChecker if ($keyed_array_var_id && isset($context->vars_in_scope[$keyed_array_var_id])) { $stmt->inferredType = clone $context->vars_in_scope[$keyed_array_var_id]; + return; } diff --git a/src/Psalm/Issue/MissingDependency.php b/src/Psalm/Issue/MissingDependency.php new file mode 100644 index 000000000..6a6b1cacf --- /dev/null +++ b/src/Psalm/Issue/MissingDependency.php @@ -0,0 +1,6 @@ + 'UndefinedClass - src/somefile.php:7', + 'error_message' => 'MissingDependency - src/somefile.php:7', ], ]; }