From 7d1423bbbaee79db0b67042b99a1ed51ee0d7796 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Mon, 22 Apr 2024 16:51:22 +0400 Subject: [PATCH] Fix psalm issues, update docs --- README.md | 15 +++++++++++---- src/Command/Run.php | 13 ++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 80e5e56e..5350a4ed 100644 --- a/README.md +++ b/README.md @@ -141,15 +141,22 @@ $responder->respond(trap($response)->return()); ### Default port -By default, the Trap server operates on port `9912`. However, if you wish to utilize a different port, you can easily -make this adjustment using the `-p` option. - -For example, to switch to port 8000, you would use the following command: +Trap automatically recognizes the type of traffic. +Therefore, there is no need to open separate ports for different protocols. +By default, it operates on port `9912`. +However, if you wish to utilize a different port, you can easily make this adjustment using the `-p` option: ```bash vendor/bin/trap -p 8000 ``` +Sometimes, it's convenient to run Trap on the same ports that [Buggregator](https://github.com/buggregator/server) +uses by default. Well, that's also possible: + +```bash +vendor/bin/trap -p 1025 -p 9912 -p 9913 -p 8000 +``` + ### Choosing Your Senders Buggregator Trap provides a variety of "senders" that dictate where the dumps will be sent. Currently, the available diff --git a/src/Command/Run.php b/src/Command/Run.php index 97552474..e10fe6eb 100644 --- a/src/Command/Run.php +++ b/src/Command/Run.php @@ -63,11 +63,18 @@ protected function execute( * @var SocketServer[] $servers */ $servers = []; - foreach ($input->getOption('port') ?: [9912] as $port) { + $ports = $input->getOption('port') ?: [9912]; + \assert(\is_array($ports)); + foreach ($ports as $port) { + \assert(\is_scalar($port)); \is_numeric($port) or throw new \InvalidArgumentException( - \sprintf('Invalid port `%s`. It must be a number.', $port), + \sprintf('Invalid port `%s`. It must be a number.', (string)$port), ); - $servers[] = new SocketServer((int)$port); + $port = (int)$port; + $port > 0 && $port < 65536 or throw new \InvalidArgumentException( + \sprintf('Invalid port `%s`. It must be in range 1-65535.', $port), + ); + $servers[] = new SocketServer($port); } /** @var non-empty-string[] $senders */