Skip to content

Commit 1e8ea32

Browse files
authored
better help page (#145)
1 parent 4f1d45f commit 1e8ea32

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

bin/phpstan-baseline-filter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@
3434
exit(254);
3535
}
3636

37-
$filterConfig = \staabm\PHPStanBaselineAnalysis\FilterConfig::fromArgs($argv[2]);
37+
try {
38+
$filterConfig = \staabm\PHPStanBaselineAnalysis\FilterConfig::fromArgs($argv[2]);
3839

39-
$exitCode = $app->start($argv[1], $filterConfig);
40-
exit($exitCode);
40+
$exitCode = $app->start($argv[1], $filterConfig);
41+
exit($exitCode);
42+
} catch (\Exception $e) {
43+
echo 'ERROR: '. $e->getMessage().PHP_EOL.PHP_EOL;
44+
$app->help();
45+
exit(254);
46+
}

lib/FilterApplication.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public function start(string $glob, FilterConfig $filterConfig): int
5151
*/
5252
public function help(): void
5353
{
54-
printf('USAGE: phpstan-baseline-filter <GLOB-PATTERN> [--exclude=<FILTER-KEY>,...] [--include=<FILTER-KEY>,...]');
54+
echo 'USAGE: phpstan-baseline-filter <GLOB-PATTERN> [--exclude=<FILTER-KEY>,...] [--include=<FILTER-KEY>,...]'.PHP_EOL.PHP_EOL;
55+
printf('valid FILTER-KEYs: %s', implode(', ', ResultPrinter::getFilterKeys()));
56+
57+
echo PHP_EOL;
5558
}
5659

5760
/**

lib/FilterConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ static public function fromArgs(string $args): self {
2424
if (str_starts_with($arg, '--exclude=')) {
2525
foreach(explode(',', substr($arg, 10)) as $key) {
2626
if (!ResultPrinter::isFilterKey($key)) {
27-
throw new \Exception("Invalid key: $key");
27+
throw new \Exception("Invalid filter key: $key");
2828
}
2929
$config->excluded[] = $key;
3030
}
3131
} else if (str_starts_with($arg, '--include=')) {
3232
foreach(explode(',', substr($arg, 10)) as $key) {
3333
if (!ResultPrinter::isFilterKey($key)) {
34-
throw new \Exception("Invalid key: $key");
34+
throw new \Exception("Invalid filter key: $key");
3535
}
3636
$config->included[] = $key;
3737
}

lib/ResultPrinter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@ final class ResultPrinter {
3232
*/
3333
public static function isFilterKey(string $filterString): bool
3434
{
35-
$keys = [
35+
36+
return in_array($filterString, self::getFilterKeys(), true);
37+
}
38+
39+
/**
40+
* @return array<self::KEY_*>
41+
*/
42+
public static function getFilterKeys(): array {
43+
return [
3644
self::KEY_CLASSES_COMPLEXITY,
3745
self::KEY_DEPRECATIONS,
3846
self::KEY_INVALID_PHPDOCS,
3947
self::KEY_UNKNOWN_TYPES,
4048
self::KEY_ANONYMOUS_VARIABLES,
4149
self::KEY_UNUSED_SYMBOLS,
4250
];
43-
44-
return in_array($filterString, $keys, true);
4551
}
4652

4753
/**

0 commit comments

Comments
 (0)