From 9a93525d33a0f2d540fcd8e7af5c70195f6b2127 Mon Sep 17 00:00:00 2001 From: Brown Date: Thu, 16 May 2019 15:06:56 -0400 Subject: [PATCH] Emit undefined docblock class error where appropriate on property fetcthes --- .../Fetch/PropertyFetchAnalyzer.php | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php index 60dc8138e..23d655bb2 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php @@ -20,6 +20,7 @@ use Psalm\Issue\ParentNotFound; use Psalm\Issue\PossiblyInvalidPropertyFetch; use Psalm\Issue\PossiblyNullPropertyFetch; use Psalm\Issue\UndefinedClass; +use Psalm\Issue\UndefinedDocblockClass; use Psalm\Issue\UndefinedPropertyFetch; use Psalm\Issue\UndefinedThisPropertyFetch; use Psalm\Issue\UninitializedProperty; @@ -425,15 +426,28 @@ class PropertyFetchAnalyzer } if (!$class_exists && !$interface_exists) { - if (IssueBuffer::accepts( - new UndefinedClass( - 'Cannot set properties of undefined class ' . $lhs_type_part->value, - new CodeLocation($statements_analyzer->getSource(), $stmt), - $lhs_type_part->value - ), - $statements_analyzer->getSuppressedIssues() - )) { - // fall through + if ($lhs_type_part->from_docblock) { + if (IssueBuffer::accepts( + new UndefinedDocblockClass( + 'Cannot set properties of undefined docblock class ' . $lhs_type_part->value, + new CodeLocation($statements_analyzer->getSource(), $stmt), + $lhs_type_part->value + ), + $statements_analyzer->getSuppressedIssues() + )) { + // fall through + } + } else { + if (IssueBuffer::accepts( + new UndefinedClass( + 'Cannot set properties of undefined class ' . $lhs_type_part->value, + new CodeLocation($statements_analyzer->getSource(), $stmt), + $lhs_type_part->value + ), + $statements_analyzer->getSuppressedIssues() + )) { + // fall through + } } return null;