Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update help panel #11000

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/Psalm/Internal/Analyzer/ProjectAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 23 additions & 4 deletions src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
use Psalm\Progress\VoidProgress;
use Psalm\Report;
use Psalm\Report\ReportOptions;
use ReflectionClass;
use RuntimeException;
use Symfony\Component\Filesystem\Path;

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;
Expand Down Expand Up @@ -67,11 +69,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;
Expand All @@ -87,6 +91,7 @@
require_once __DIR__ . '/../Composer.php';
require_once __DIR__ . '/../IncludeCollector.php';
require_once __DIR__ . '/../../IssueBuffer.php';
require_once __DIR__ . '/../../Report.php';

/**
* @internal
Expand Down Expand Up @@ -1250,6 +1255,21 @@ 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 ");

/** @psalm-suppress ImpureMethodCall */
$reports = array_keys(Report::getMapping());
sort($reports);
$reportFormats = wordwrap('"' . implode('", "', $reports) . '"', 75, "\n ");

return <<<HELP
Usage:
psalm [options] [file...]
Expand Down Expand Up @@ -1333,8 +1353,8 @@ private static function getHelpText(): string

--output-format=console
Changes the output format.
Available formats: compact, console, text, emacs, json, pylint, xml, checkstyle, junit, sonarqube,
github, phpstorm, codeclimate, by-issue-level
Available formats:
$outputFormats

--no-progress
Disable the progress indicator
Expand All @@ -1348,8 +1368,7 @@ private static function getHelpText(): string
Reports:
--report=PATH
The path where to output report file. The output format is based on the file extension.
(Currently supported formats: ".json", ".xml", ".txt", ".emacs", ".pylint", ".console",
".sarif", "checkstyle.xml", "sonarqube.json", "codeclimate.json", "summary.json", "junit.xml")
(Currently supported formats: $reportFormats)

--report-show-info[=BOOLEAN]
Whether the report should include non-errors in its output (defaults to true)
Expand Down
23 changes: 23 additions & 0 deletions src/Psalm/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,27 @@ protected function xmlEncode(string $data): string
}

abstract public function create(): string;

/**
* @return array<string, self::TYPE_*>
*/
public static function getMapping(): array
{
return [
'checkstyle.xml' => 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,
];
}
}
Loading