Skip to content

Commit 1870979

Browse files
authored
Fix PHPStan errors (#182)
1 parent 9c0d07a commit 1870979

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/FilterConfig.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,49 @@ final class FilterConfig {
1111
/**
1212
* @var array<ResultPrinter::KEY_*>
1313
*/
14-
public array $excluded = [];
14+
private array $excluded;
1515
/**
1616
* @var array<ResultPrinter::KEY_*>
1717
*/
18-
public array $included = [];
18+
private array $included;
19+
20+
/**
21+
* @param array<ResultPrinter::KEY_*> $excluded
22+
* @param array<ResultPrinter::KEY_*> $included
23+
*/
24+
private function __construct(array $excluded, array $included) {
25+
$this->excluded = $excluded;
26+
$this->included = $included;
27+
}
1928

2029
static public function fromArgs(string $args): self {
21-
$config = new FilterConfig();
2230
$args = explode(' ', $args);
31+
32+
$excluded = [];
33+
$included = [];
2334
foreach ($args as $arg) {
2435
if (str_starts_with($arg, '--exclude=')) {
2536
foreach(explode(',', substr($arg, 10)) as $key) {
2637
if (!ResultPrinter::isFilterKey($key)) {
2738
throw new \Exception("Invalid filter key: $key");
2839
}
29-
$config->excluded[] = $key;
40+
$excluded[] = $key;
3041
}
3142
} else if (str_starts_with($arg, '--include=')) {
3243
foreach(explode(',', substr($arg, 10)) as $key) {
3344
if (!ResultPrinter::isFilterKey($key)) {
3445
throw new \Exception("Invalid filter key: $key");
3546
}
36-
$config->included[] = $key;
47+
$included[] = $key;
3748
}
3849
}
3950
}
4051

41-
if (count($config->excluded) > 0 && count($config->included) > 0) {
52+
if (count($excluded) > 0 && count($included) > 0) {
4253
throw new \Exception("Cannot use --exclude and --include at the same time");
4354
}
4455

45-
return $config;
56+
return new self($excluded, $included);
4657
}
4758

4859
public function isExcluding(): bool {

0 commit comments

Comments
 (0)