Skip to content

Commit

Permalink
Fix #763 - always force rescanning of files if issues were found firs…
Browse files Browse the repository at this point in the history
…t time around
  • Loading branch information
muglug committed May 29, 2018
1 parent d55afc1 commit 14f3f7a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/Psalm/Codebase/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Storage/ClassLikeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ class ClassLikeStorage
*/
public $hash = '';

/**
* @var bool
*/
public $has_visitor_issues = false;

/**
* @param string $name
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Storage/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class FileStorage
*/
public $hash = '';

/**
* @var bool
*/
public $has_visitor_issues = false;

/**
* @param string $file_path
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Psalm/Storage/FunctionLikeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ class FunctionLikeStorage
* @var array<int, Assertion>
*/
public $if_false_assertions = [];

/**
* @var bool
*/
public $has_visitor_issues = false;
}
38 changes: 26 additions & 12 deletions src/Psalm/Visitor/DependencyFinderVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -616,15 +622,21 @@ 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
) {
$this->queue_strings_as_possible_type = false;

$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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -1331,7 +1345,7 @@ private function improveParamsFromDocblock(
$code_location
)
)) {
// fall through
$storage->has_visitor_issues = true;
}

continue;
Expand Down Expand Up @@ -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(
Expand All @@ -1459,7 +1473,7 @@ private function visitPropertyDeclaration(
new CodeLocation($this->file_scanner, $stmt, null, true)
)
)) {
// fall through
$storage->has_visitor_issues = true;
}
}
}
Expand Down

0 comments on commit 14f3f7a

Please sign in to comment.