mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Only write files if they’re changed
This commit is contained in:
parent
9a3cb742cb
commit
fc6b663c8a
@ -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,7 +1000,13 @@ class ProjectChecker
|
||||
. substr($existing_contents, $manipulation->end);
|
||||
}
|
||||
|
||||
$this->file_provider->setContents($file_path, $existing_contents);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user