Skip to content

Commit d77790b

Browse files
authored
Merge pull request #11000 from llaville/dynamic-help-text
Update help panel
2 parents 0294324 + bce59cf commit d77790b

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

src/Psalm/Internal/Analyzer/ProjectAnalyzer.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,21 +329,7 @@ public static function getFileReportOptions(array $report_file_paths, bool $show
329329
{
330330
$report_options = [];
331331

332-
$mapping = [
333-
'checkstyle.xml' => Report::TYPE_CHECKSTYLE,
334-
'sonarqube.json' => Report::TYPE_SONARQUBE,
335-
'codeclimate.json' => Report::TYPE_CODECLIMATE,
336-
'summary.json' => Report::TYPE_JSON_SUMMARY,
337-
'junit.xml' => Report::TYPE_JUNIT,
338-
'.xml' => Report::TYPE_XML,
339-
'.json' => Report::TYPE_JSON,
340-
'.txt' => Report::TYPE_TEXT,
341-
'.emacs' => Report::TYPE_EMACS,
342-
'.pylint' => Report::TYPE_PYLINT,
343-
'.console' => Report::TYPE_CONSOLE,
344-
'.sarif' => Report::TYPE_SARIF,
345-
'count.txt' => Report::TYPE_COUNT,
346-
];
332+
$mapping = Report::getMapping();
347333

348334
foreach ($report_file_paths as $report_file_path) {
349335
foreach ($mapping as $extension => $type) {

src/Psalm/Internal/Cli/Psalm.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
use Psalm\Progress\VoidProgress;
3232
use Psalm\Report;
3333
use Psalm\Report\ReportOptions;
34+
use ReflectionClass;
3435
use RuntimeException;
3536
use Symfony\Component\Filesystem\Path;
3637

3738
use function array_filter;
3839
use function array_key_exists;
40+
use function array_keys;
3941
use function array_map;
4042
use function array_merge;
4143
use function array_slice;
@@ -67,11 +69,13 @@
6769
use function preg_replace;
6870
use function realpath;
6971
use function setlocale;
72+
use function sort;
7073
use function str_repeat;
7174
use function str_replace;
7275
use function strlen;
7376
use function strpos;
7477
use function substr;
78+
use function wordwrap;
7579

7680
use const DIRECTORY_SEPARATOR;
7781
use const JSON_THROW_ON_ERROR;
@@ -87,6 +91,7 @@
8791
require_once __DIR__ . '/../Composer.php';
8892
require_once __DIR__ . '/../IncludeCollector.php';
8993
require_once __DIR__ . '/../../IssueBuffer.php';
94+
require_once __DIR__ . '/../../Report.php';
9095

9196
/**
9297
* @internal
@@ -1250,6 +1255,21 @@ private static function generateStubs(
12501255
*/
12511256
private static function getHelpText(): string
12521257
{
1258+
$formats = [];
1259+
/** @var string $value */
1260+
foreach ((new ReflectionClass(Report::class))->getConstants() as $constant => $value) {
1261+
if (strpos($constant, 'TYPE_') === 0) {
1262+
$formats[] = $value;
1263+
}
1264+
}
1265+
sort($formats);
1266+
$outputFormats = wordwrap(implode(', ', $formats), 75, "\n ");
1267+
1268+
/** @psalm-suppress ImpureMethodCall */
1269+
$reports = array_keys(Report::getMapping());
1270+
sort($reports);
1271+
$reportFormats = wordwrap('"' . implode('", "', $reports) . '"', 75, "\n ");
1272+
12531273
return <<<HELP
12541274
Usage:
12551275
psalm [options] [file...]
@@ -1333,8 +1353,8 @@ private static function getHelpText(): string
13331353
13341354
--output-format=console
13351355
Changes the output format.
1336-
Available formats: compact, console, text, emacs, json, pylint, xml, checkstyle, junit, sonarqube,
1337-
github, phpstorm, codeclimate, by-issue-level
1356+
Available formats:
1357+
$outputFormats
13381358
13391359
--no-progress
13401360
Disable the progress indicator
@@ -1348,8 +1368,7 @@ private static function getHelpText(): string
13481368
Reports:
13491369
--report=PATH
13501370
The path where to output report file. The output format is based on the file extension.
1351-
(Currently supported formats: ".json", ".xml", ".txt", ".emacs", ".pylint", ".console",
1352-
".sarif", "checkstyle.xml", "sonarqube.json", "codeclimate.json", "summary.json", "junit.xml")
1371+
(Currently supported formats: $reportFormats)
13531372
13541373
--report-show-info[=BOOLEAN]
13551374
Whether the report should include non-errors in its output (defaults to true)

src/Psalm/Report.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,27 @@ protected function xmlEncode(string $data): string
9797
}
9898

9999
abstract public function create(): string;
100+
101+
/**
102+
* @return array<string, self::TYPE_*>
103+
*/
104+
public static function getMapping(): array
105+
{
106+
return [
107+
'checkstyle.xml' => self::TYPE_CHECKSTYLE,
108+
'sonarqube.json' => self::TYPE_SONARQUBE,
109+
'codeclimate.json' => self::TYPE_CODECLIMATE,
110+
'summary.json' => self::TYPE_JSON_SUMMARY,
111+
'junit.xml' => self::TYPE_JUNIT,
112+
'.xml' => self::TYPE_XML,
113+
'.sarif.json' => self::TYPE_SARIF,
114+
'.json' => self::TYPE_JSON,
115+
'.txt' => self::TYPE_TEXT,
116+
'.emacs' => self::TYPE_EMACS,
117+
'.pylint' => self::TYPE_PYLINT,
118+
'.console' => self::TYPE_CONSOLE,
119+
'.sarif' => self::TYPE_SARIF,
120+
'count.txt' => self::TYPE_COUNT,
121+
];
122+
}
100123
}

0 commit comments

Comments
 (0)