From 14f3f7a998f9c6828420ce251d5502dc347e6968 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 29 May 2018 10:13:26 -0400 Subject: [PATCH] Fix #763 - always force rescanning of files if issues were found first time around --- src/Psalm/Codebase/Scanner.php | 4 +- src/Psalm/Storage/ClassLikeStorage.php | 5 +++ src/Psalm/Storage/FileStorage.php | 5 +++ src/Psalm/Storage/FunctionLikeStorage.php | 5 +++ src/Psalm/Visitor/DependencyFinderVisitor.php | 38 +++++++++++++------ 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Psalm/Codebase/Scanner.php b/src/Psalm/Codebase/Scanner.php index f6d4b0115e4..1a32df2f0f2 100644 --- a/src/Psalm/Codebase/Scanner.php +++ b/src/Psalm/Codebase/Scanner.php @@ -312,7 +312,9 @@ private function scanFile( ); if (!$from_cache) { - $this->file_storage_provider->cache->writeToCache($file_storage, $file_contents); + if (!$file_storage->has_visitor_issues) { + $this->file_storage_provider->cache->writeToCache($file_storage, $file_contents); + } } else { foreach ($file_storage->included_file_paths as $include_file_path) { $this->addFileToShallowScan($include_file_path); diff --git a/src/Psalm/Storage/ClassLikeStorage.php b/src/Psalm/Storage/ClassLikeStorage.php index 4422f4826d5..0c24910e5dc 100644 --- a/src/Psalm/Storage/ClassLikeStorage.php +++ b/src/Psalm/Storage/ClassLikeStorage.php @@ -232,6 +232,11 @@ class ClassLikeStorage */ public $hash = ''; + /** + * @var bool + */ + public $has_visitor_issues = false; + /** * @param string $name */ diff --git a/src/Psalm/Storage/FileStorage.php b/src/Psalm/Storage/FileStorage.php index 1e9deb4a644..f4c64ae495f 100644 --- a/src/Psalm/Storage/FileStorage.php +++ b/src/Psalm/Storage/FileStorage.php @@ -64,6 +64,11 @@ class FileStorage */ public $hash = ''; + /** + * @var bool + */ + public $has_visitor_issues = false; + /** * @param string $file_path */ diff --git a/src/Psalm/Storage/FunctionLikeStorage.php b/src/Psalm/Storage/FunctionLikeStorage.php index 53bd0348b61..bf2eada0c6b 100644 --- a/src/Psalm/Storage/FunctionLikeStorage.php +++ b/src/Psalm/Storage/FunctionLikeStorage.php @@ -110,4 +110,9 @@ class FunctionLikeStorage * @var array */ public $if_false_assertions = []; + + /** + * @var bool + */ + public $has_visitor_issues = false; } diff --git a/src/Psalm/Visitor/DependencyFinderVisitor.php b/src/Psalm/Visitor/DependencyFinderVisitor.php index 58ed722e2c7..4b83f7490ac 100644 --- a/src/Psalm/Visitor/DependencyFinderVisitor.php +++ b/src/Psalm/Visitor/DependencyFinderVisitor.php @@ -183,7 +183,7 @@ public function enterNode(PhpParser\Node $node) new CodeLocation($this->file_scanner, $node, null, true) ) )) { - // fall through + $this->file_storage->has_visitor_issues = true; } return PhpParser\NodeTraverser::STOP_TRAVERSAL; @@ -214,12 +214,14 @@ public function enterNode(PhpParser\Node $node) $doc_comment->getLine() ); } catch (DocblockParseException $e) { - IssueBuffer::accepts( + if (IssueBuffer::accepts( new InvalidDocblock( $e->getMessage() . ' in docblock for ' . implode('.', $this->fq_classlike_names), new CodeLocation($this->file_scanner, $node, null, true) ) - ); + )) { + $storage->has_visitor_issues = true; + } } if ($docblock_info) { @@ -600,6 +602,10 @@ public function leaveNode(PhpParser\Node $node) $classlike_storage = array_pop($this->classlike_storages); + if ($classlike_storage->has_visitor_issues) { + $this->file_storage->has_visitor_issues = true; + } + $this->class_template_types = []; if ($this->after_classlike_check_plugins) { @@ -616,7 +622,9 @@ public function leaveNode(PhpParser\Node $node) } } - $this->codebase->cacheClassLikeStorage($classlike_storage, $this->file_path); + if (!$this->file_storage->has_visitor_issues) { + $this->codebase->cacheClassLikeStorage($classlike_storage, $this->file_path); + } } elseif ($node instanceof PhpParser\Node\Stmt\Function_ || $node instanceof PhpParser\Node\Stmt\ClassMethod ) { @@ -624,7 +632,11 @@ public function leaveNode(PhpParser\Node $node) $this->function_template_types = []; } elseif ($node instanceof PhpParser\Node\FunctionLike) { - array_pop($this->functionlike_storages); + $functionlike_storage = array_pop($this->functionlike_storages); + + if ($functionlike_storage->has_visitor_issues) { + $this->file_storage->has_visitor_issues = true; + } } return null; @@ -755,6 +767,8 @@ private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_m new CodeLocation($this->file_scanner, $param, null, true) ) )) { + $storage->has_visitor_issues = true; + continue; } } @@ -774,7 +788,7 @@ private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_m new CodeLocation($this->file_scanner, $param, null, true) ) )) { - // fall through + $storage->has_visitor_issues = true; } } } else { @@ -936,7 +950,7 @@ private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_m new CodeLocation($this->file_scanner, $stmt, null, true) ) )) { - // fall through + $storage->has_visitor_issues = true; } $docblock_info = null; @@ -947,7 +961,7 @@ private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_m new CodeLocation($this->file_scanner, $stmt, null, true) ) )) { - // fall through + $storage->has_visitor_issues = true; } $docblock_info = null; @@ -1144,7 +1158,7 @@ private function registerFunctionLike(PhpParser\Node\FunctionLike $stmt, $fake_m new CodeLocation($this->file_scanner, $stmt, null, true) ) )) { - // fall through + $storage->has_visitor_issues = true; } } } @@ -1331,7 +1345,7 @@ private function improveParamsFromDocblock( $code_location ) )) { - // fall through + $storage->has_visitor_issues = true; } continue; @@ -1450,7 +1464,7 @@ private function visitPropertyDeclaration( new CodeLocation($this->file_scanner, $stmt, null, true) ) )) { - // fall through + $storage->has_visitor_issues = true; } } catch (DocblockParseException $e) { if (IssueBuffer::accepts( @@ -1459,7 +1473,7 @@ private function visitPropertyDeclaration( new CodeLocation($this->file_scanner, $stmt, null, true) ) )) { - // fall through + $storage->has_visitor_issues = true; } } }