Skip to content

Commit

Permalink
Fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 9, 2024
1 parent 9c0d07a commit 1ae1f41
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/FilterConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,49 @@ final class FilterConfig {
/**
* @var array<ResultPrinter::KEY_*>
*/
public array $excluded = [];
public array $excluded;
/**
* @var array<ResultPrinter::KEY_*>
*/
public array $included = [];
public array $included;

/**
* @param array<ResultPrinter::KEY_*> $excluded
* @param array<ResultPrinter::KEY_*> $included
*/
private function __construct(array $excluded, array $included) {
$this->excluded = $excluded;
$this->included = $included;
}

static public function fromArgs(string $args): self {
$config = new FilterConfig();
$args = explode(' ', $args);

$excluded = [];
$included = [];
foreach ($args as $arg) {
if (str_starts_with($arg, '--exclude=')) {
foreach(explode(',', substr($arg, 10)) as $key) {
if (!ResultPrinter::isFilterKey($key)) {
throw new \Exception("Invalid filter key: $key");
}
$config->excluded[] = $key;
$excluded[] = $key;
}
} else if (str_starts_with($arg, '--include=')) {
foreach(explode(',', substr($arg, 10)) as $key) {
if (!ResultPrinter::isFilterKey($key)) {
throw new \Exception("Invalid filter key: $key");
}
$config->included[] = $key;
$included[] = $key;
}
}
}

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

return $config;
return new self($excluded, $included);
}

public function isExcluding(): bool {
Expand Down

0 comments on commit 1ae1f41

Please sign in to comment.