From ae8ccdbcd759aa7a3ca5bbfa9d555f3fb09bfeba Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 3 Jun 2019 11:20:42 -0400 Subject: [PATCH] Add add info notification to progress --- src/Psalm/Internal/Codebase/Analyzer.php | 36 ++++++++++++++++++++---- src/Psalm/Progress/DefaultProgress.php | 4 +-- src/Psalm/Progress/LongProgress.php | 18 ++++++++---- src/Psalm/Progress/Progress.php | 2 +- src/psalm.php | 2 +- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 2ac3297ba..f9463fbb9 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -245,9 +245,27 @@ class Analyzer $this->progress->start(count($this->files_to_analyze)); - $task_done_closure = function (array $issues): void { - $this->progress->taskDone(count($issues) === 0); - }; + $task_done_closure = + /** + * @param array $issues + */ + function (array $issues): void { + $has_error = false; + $has_info = false; + + foreach ($issues as $issue) { + if ($issue['severity'] === 'error') { + $has_error = true; + break; + } + + if ($issue['severity'] === 'info') { + $has_info = true; + } + } + + $this->progress->taskDone($has_error ? 2 : ($has_info ? 1 : 0)); + }; if ($pool_size > 1 && count($this->files_to_analyze) > $pool_size) { $process_file_paths = []; @@ -458,11 +476,17 @@ class Analyzer } } + /** + * @return array + */ private function getFileIssues(string $file_path): array { - return array_filter(IssueBuffer::getIssuesData(), function (array $issue) use ($file_path): bool { - return $issue['file_path'] === $file_path; - }); + return array_filter( + IssueBuffer::getIssuesData(), + function (array $issue) use ($file_path): bool { + return $issue['file_path'] === $file_path; + } + ); } /** diff --git a/src/Psalm/Progress/DefaultProgress.php b/src/Psalm/Progress/DefaultProgress.php index 82aeca24a..bd9241ec9 100644 --- a/src/Psalm/Progress/DefaultProgress.php +++ b/src/Psalm/Progress/DefaultProgress.php @@ -5,7 +5,7 @@ class DefaultProgress extends LongProgress { const TOO_MANY_FILES = 1500; - public function taskDone(bool $successful): void + public function taskDone(int $level): void { if ($this->number_of_tasks > self::TOO_MANY_FILES) { ++$this->progress; @@ -17,7 +17,7 @@ class DefaultProgress extends LongProgress $this->write($inner_progress . ' ' . $this->getOverview() . "\r"); } else { - parent::taskDone($successful); + parent::taskDone($level); } } diff --git a/src/Psalm/Progress/LongProgress.php b/src/Psalm/Progress/LongProgress.php index 7972d4fa7..832f62f86 100644 --- a/src/Psalm/Progress/LongProgress.php +++ b/src/Psalm/Progress/LongProgress.php @@ -12,11 +12,15 @@ class LongProgress extends Progress protected $progress = 0; /** @var bool */ - protected $print_failures = false; + protected $print_errors = false; - public function __construct(bool $print_failures = true) + /** @var bool */ + protected $print_infos = false; + + public function __construct(bool $print_errors = true, bool $print_infos = true) { - $this->print_failures = $print_failures; + $this->print_errors = $print_errors; + $this->print_infos = $print_infos; } public function startScanningFiles(): void @@ -45,12 +49,14 @@ class LongProgress extends Progress $this->progress = 0; } - public function taskDone(bool $successful): void + public function taskDone(int $level): void { - if ($successful || !$this->print_failures) { + if ($level === 0 || ($level === 1 && !$this->print_infos) || !$this->print_errors) { $this->write(self::doesTerminalSupportUtf8() ? '░' : '_'); + } elseif ($level === 1) { + $this->write('I'); } else { - $this->write('F'); + $this->write('E'); } ++$this->progress; diff --git a/src/Psalm/Progress/Progress.php b/src/Psalm/Progress/Progress.php index 6c1e8dfd0..45f4312ad 100644 --- a/src/Psalm/Progress/Progress.php +++ b/src/Psalm/Progress/Progress.php @@ -32,7 +32,7 @@ abstract class Progress { } - public function taskDone(bool $successful): void + public function taskDone(int $level): void { } diff --git a/src/psalm.php b/src/psalm.php index 5eab5e08f..3693cb3fa 100644 --- a/src/psalm.php +++ b/src/psalm.php @@ -505,7 +505,7 @@ if (isset($_SERVER['TRAVIS']) $debug = array_key_exists('debug', $options) || array_key_exists('debug-by-line', $options); $progress = $debug ? new DebugProgress() - : (isset($options['no-progress']) ? new VoidProgress() : new DefaultProgress(!$config->error_baseline)); + : (isset($options['no-progress']) ? new VoidProgress() : new DefaultProgress(!$config->error_baseline, $show_info)); if (isset($options['no-cache'])) { $providers = new Provider\Providers(