Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/DNS/Adapter/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ class Swoole extends Adapter

protected string $host;
protected int $port;
protected int $numWorkers;
protected int $maxCoroutines;

public function __construct(string $host = '0.0.0.0', int $port = 53)
public function __construct(string $host = '0.0.0.0', int $port = 53, int $numWorkers = 1, int $maxCoroutines = 3000)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add PHPDoc for new constructor parameters.

The constructor signature now accepts two new parameters, but they lack documentation. Since this is a public API, adding PHPDoc comments would help users understand the purpose and valid ranges of numWorkers and maxCoroutines.

🔎 Suggested PHPDoc addition
+    /**
+     * @param string $host The host address to bind to
+     * @param int $port The port to listen on
+     * @param int $numWorkers The number of worker processes (default: 1)
+     * @param int $maxCoroutines The maximum number of coroutines (default: 3000)
+     */
     public function __construct(string $host = '0.0.0.0', int $port = 53, int $numWorkers = 1, int $maxCoroutines = 3000)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function __construct(string $host = '0.0.0.0', int $port = 53, int $numWorkers = 1, int $maxCoroutines = 3000)
/**
* @param string $host The host address to bind to
* @param int $port The port to listen on
* @param int $numWorkers The number of worker processes (default: 1)
* @param int $maxCoroutines The maximum number of coroutines (default: 3000)
*/
public function __construct(string $host = '0.0.0.0', int $port = 53, int $numWorkers = 1, int $maxCoroutines = 3000)
🤖 Prompt for AI Agents
In src/DNS/Adapter/Swoole.php around line 21, the constructor's new parameters
$numWorkers and $maxCoroutines lack PHPDoc; add a docblock above the constructor
documenting each parameter (string $host, int $port, int $numWorkers, int
$maxCoroutines) with a brief description and valid ranges/defaults (e.g.,
$numWorkers: number of Swoole worker processes, positive int, default 1;
$maxCoroutines: maximum coroutines per worker, positive int, typical limit and
default 3000), and include @param tags for each parameter and an @throws or @see
tag if relevant to runtime limits.

{
$this->host = $host;
$this->port = $port;
$this->numWorkers = $numWorkers;
$this->maxCoroutines = $maxCoroutines;
$this->server = new Server($this->host, $this->port, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);
$this->server->set([
'worker_num' => $this->numWorkers,
'max_coroutine' => $this->maxCoroutines,
]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DNS/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected function handleError(Throwable $error): void
*/
protected function onPacket(string $buffer, string $ip, int $port): string
{
$span = Span::init();
$span = Span::init('dns.packet');
$span->set('client.ip', $ip);

$question = null;
Expand Down
3 changes: 1 addition & 2 deletions tests/resources/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
$dns->setDebug(false);

$dns->onWorkerStart(function (Server $server, int $workerId) {
$span = Span::init();
$span->set('action', 'dns.worker.start');
$span = Span::init('dns.worker.start');
$span->set('worker.id', $workerId);
$span->finish();
});
Expand Down