From 2fbfc429b7f8babc88389b4331383f17d048fd5f Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 14 Jan 2021 16:44:20 -0500 Subject: [PATCH] Only create after analysis event if they exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5008 - this does some git execing, so we don’t want it to always run --- src/Psalm/IssueBuffer.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 576c1bd42..513fade48 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -544,22 +544,26 @@ class IssueBuffer $source_control_info = null; $build_info = (new \Psalm\Internal\ExecutionEnvironment\BuildInfoCollector($_SERVER))->collect(); - try { - $source_control_info = (new \Psalm\Internal\ExecutionEnvironment\GitInfoCollector())->collect(); - } catch (\RuntimeException $e) { - // do nothing + if ($codebase->config->eventDispatcher->after_analysis + || $codebase->config->eventDispatcher->legacy_after_analysis + ) { + try { + $source_control_info = (new \Psalm\Internal\ExecutionEnvironment\GitInfoCollector())->collect(); + } catch (\RuntimeException $e) { + // do nothing + } + + /** @psalm-suppress ArgumentTypeCoercion due to Psalm bug */ + $event = new AfterAnalysisEvent( + $codebase, + $issues_data, + $build_info, + $source_control_info + ); + + $codebase->config->eventDispatcher->dispatchAfterAnalysis($event); } - /** @psalm-suppress ArgumentTypeCoercion due to Psalm bug */ - $event = new AfterAnalysisEvent( - $codebase, - $issues_data, - $build_info, - $source_control_info - ); - - $codebase->config->eventDispatcher->dispatchAfterAnalysis($event); - foreach ($project_analyzer->generated_report_options as $report_options) { if (!$report_options->output_path) { throw new \UnexpectedValueException('Output path should not be null here');