1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Only write files if they’re changed

This commit is contained in:
Matthew Brown 2017-09-16 12:52:46 -04:00
parent 9a3cb742cb
commit fc6b663c8a

View File

@ -974,20 +974,23 @@ class ProjectChecker
if ($this->update_docblocks) {
foreach ($this->files_to_report as $file_path) {
$this->updateFile($file_path);
$this->updateFile($file_path, true);
}
}
}
/**
* @param string $file_path
* @param bool $output_changes to console
*
* @return void
*/
public function updateFile($file_path)
public function updateFile($file_path, $output_changes = false)
{
$file_manipulations = FunctionDocblockManipulator::getManipulationsForFile($file_path);
$docblock_update_count = count($file_manipulations);
$existing_contents = $this->getFileContents($file_path);
foreach (array_reverse($file_manipulations) as $manipulation) {
@ -997,8 +1000,14 @@ class ProjectChecker
. substr($existing_contents, $manipulation->end);
}
if ($docblock_update_count) {
if ($output_changes) {
echo 'Adding/updating ' . $docblock_update_count . ' docblocks in ' . $file_path . PHP_EOL;
}
$this->file_provider->setContents($file_path, $existing_contents);
}
}
/**
* @param string $method_id