Skip to content

Commit

Permalink
Make the PORT parameter a list
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Apr 22, 2024
1 parent aa66a15 commit a8bef6b
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ final class Run extends Command implements SignalableCommandInterface

public function configure(): void
{
$this->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'Port to listen', 9912);
$this->addOption(
'port',
'p',
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Port to listen',
[9912],
);
$this->addOption(
'sender',
's',
Expand All @@ -52,14 +58,25 @@ protected function execute(
$output->writeln(\sprintf('<fg=yellow;options=bold>%s</> <info>v%s</>', Info::NAME, Info::VERSION));
$output->write(Info::LOGO_CLI_COLOR . "\n", true, OutputInterface::OUTPUT_RAW);

$port = (int)$input->getOption('port') ?: 9912;
/**
* Prepare port listeners
* @var SocketServer[] $servers
*/
$servers = [];
foreach ($input->getOption('port') ?: [9912] as $port) {
\is_numeric($port) or throw new \InvalidArgumentException(
\sprintf('Invalid port `%s`. It must be a number.', $port),

Check failure on line 68 in src/Command/Run.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

MixedArgument

src/Command/Run.php:68:73: MixedArgument: Argument 2 of sprintf cannot be mixed, expecting float|int|object{__tostring()}|string (see https://psalm.dev/030)

Check failure on line 68 in src/Command/Run.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

MixedArgument

src/Command/Run.php:68:73: MixedArgument: Argument 2 of sprintf cannot be mixed, expecting float|int|object{__tostring()}|string (see https://psalm.dev/030)
);
$servers[] = new SocketServer((int)$port);

Check failure on line 70 in src/Command/Run.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

ArgumentTypeCoercion

src/Command/Run.php:70:47: ArgumentTypeCoercion: Argument 1 of Buggregator\Trap\Config\SocketServer::__construct expects int<1, 65535>, but parent type int provided (see https://psalm.dev/193)

Check failure on line 70 in src/Command/Run.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)

ArgumentTypeCoercion

src/Command/Run.php:70:47: ArgumentTypeCoercion: Argument 1 of Buggregator\Trap\Config\SocketServer::__construct expects int<1, 65535>, but parent type int provided (see https://psalm.dev/193)
}

/** @var non-empty-string[] $senders */
$senders = (array)$input->getOption('sender');

$registry = $this->createRegistry($output);

$this->app = new Application(
[new SocketServer($port)],
$servers,
new Logger($output),
senders: $registry->getSenders($senders),
withFrontend: $input->getOption('ui') !== false,
Expand Down

0 comments on commit a8bef6b

Please sign in to comment.