From fbf07dbd3050446a8180c18c6c77e630132352b4 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 2 Jun 2024 12:33:18 +0000 Subject: [PATCH 1/3] up-to-date output-format list --- src/Psalm/Internal/Cli/Psalm.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index 30b6679ecd4..e9156795953 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -31,6 +31,7 @@ use Psalm\Progress\VoidProgress; use Psalm\Report; use Psalm\Report\ReportOptions; +use ReflectionClass; use RuntimeException; use Symfony\Component\Filesystem\Path; @@ -67,11 +68,13 @@ use function preg_replace; use function realpath; use function setlocale; +use function sort; use function str_repeat; use function str_replace; use function strlen; use function strpos; use function substr; +use function wordwrap; use const DIRECTORY_SEPARATOR; use const JSON_THROW_ON_ERROR; @@ -87,6 +90,7 @@ require_once __DIR__ . '/../Composer.php'; require_once __DIR__ . '/../IncludeCollector.php'; require_once __DIR__ . '/../../IssueBuffer.php'; +require_once __DIR__ . '/../../Report.php'; /** * @internal @@ -1250,6 +1254,16 @@ private static function generateStubs( */ private static function getHelpText(): string { + $formats = []; + /** @var string $value */ + foreach ((new ReflectionClass(Report::class))->getConstants() as $constant => $value) { + if (strpos($constant, 'TYPE_') === 0) { + $formats[] = $value; + } + } + sort($formats); + $outputFormats = wordwrap(implode(', ', $formats), 75, "\n "); + return << Date: Sun, 2 Jun 2024 13:04:18 +0000 Subject: [PATCH 2/3] up-to-date report list --- .../Internal/Analyzer/ProjectAnalyzer.php | 16 +-------------- src/Psalm/Internal/Cli/Psalm.php | 8 ++++++-- src/Psalm/Report.php | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index ed22c279d97..d5e9d090dc4 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -329,21 +329,7 @@ public static function getFileReportOptions(array $report_file_paths, bool $show { $report_options = []; - $mapping = [ - 'checkstyle.xml' => Report::TYPE_CHECKSTYLE, - 'sonarqube.json' => Report::TYPE_SONARQUBE, - 'codeclimate.json' => Report::TYPE_CODECLIMATE, - 'summary.json' => Report::TYPE_JSON_SUMMARY, - 'junit.xml' => Report::TYPE_JUNIT, - '.xml' => Report::TYPE_XML, - '.json' => Report::TYPE_JSON, - '.txt' => Report::TYPE_TEXT, - '.emacs' => Report::TYPE_EMACS, - '.pylint' => Report::TYPE_PYLINT, - '.console' => Report::TYPE_CONSOLE, - '.sarif' => Report::TYPE_SARIF, - 'count.txt' => Report::TYPE_COUNT, - ]; + $mapping = Report::getMapping(); foreach ($report_file_paths as $report_file_path) { foreach ($mapping as $extension => $type) { diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index e9156795953..dcfb903787e 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -37,6 +37,7 @@ use function array_filter; use function array_key_exists; +use function array_keys; use function array_map; use function array_merge; use function array_slice; @@ -1264,6 +1265,10 @@ private static function getHelpText(): string sort($formats); $outputFormats = wordwrap(implode(', ', $formats), 75, "\n "); + $reports = array_keys(Report::getMapping()); + sort($reports); + $reportFormats = wordwrap('"' . implode('", "', $reports) . '"', 75, "\n "); + return << self::TYPE_CHECKSTYLE, + 'sonarqube.json' => self::TYPE_SONARQUBE, + 'codeclimate.json' => self::TYPE_CODECLIMATE, + 'summary.json' => self::TYPE_JSON_SUMMARY, + 'junit.xml' => self::TYPE_JUNIT, + '.xml' => self::TYPE_XML, + '.sarif.json' => self::TYPE_SARIF, + '.json' => self::TYPE_JSON, + '.txt' => self::TYPE_TEXT, + '.emacs' => self::TYPE_EMACS, + '.pylint' => self::TYPE_PYLINT, + '.console' => self::TYPE_CONSOLE, + '.sarif' => self::TYPE_SARIF, + 'count.txt' => self::TYPE_COUNT, + ]; + } } From bce59cf5ad31fe737d58729196f6c0ac134d2bff Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sun, 2 Jun 2024 13:34:36 +0000 Subject: [PATCH 3/3] fix psalm errors --- src/Psalm/Internal/Cli/Psalm.php | 1 + src/Psalm/Report.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index dcfb903787e..99d87b52269 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -1265,6 +1265,7 @@ private static function getHelpText(): string sort($formats); $outputFormats = wordwrap(implode(', ', $formats), 75, "\n "); + /** @psalm-suppress ImpureMethodCall */ $reports = array_keys(Report::getMapping()); sort($reports); $reportFormats = wordwrap('"' . implode('", "', $reports) . '"', 75, "\n "); diff --git a/src/Psalm/Report.php b/src/Psalm/Report.php index f60483d82ec..3ed578c06cf 100644 --- a/src/Psalm/Report.php +++ b/src/Psalm/Report.php @@ -98,6 +98,9 @@ protected function xmlEncode(string $data): string abstract public function create(): string; + /** + * @return array + */ public static function getMapping(): array { return [