From 597f6916d9a1e512bc3fb0597fbc2cfe264b4a28 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Tue, 6 Aug 2024 22:11:04 +0200 Subject: [PATCH 1/4] Use property promotion --- src/Connection/UdpConnection.php | 22 +++------------------- src/Protocols/Http/Chunk.php | 15 ++------------- src/Protocols/Http/Request.php | 13 +------------ src/Protocols/Http/ServerSentEvents.php | 12 +----------- 4 files changed, 7 insertions(+), 55 deletions(-) diff --git a/src/Connection/UdpConnection.php b/src/Connection/UdpConnection.php index 1a25af0af..dac804107 100644 --- a/src/Connection/UdpConnection.php +++ b/src/Connection/UdpConnection.php @@ -45,31 +45,15 @@ class UdpConnection extends ConnectionInterface implements JsonSerializable */ public string $transport = 'udp'; - /** - * Udp socket. - * - * @var resource - */ - protected $socket; - - /** - * Remote address. - * - * @var string - */ - protected string $remoteAddress = ''; - /** * Construct. * * @param resource $socket * @param string $remoteAddress */ - public function __construct($socket, string $remoteAddress) - { - $this->socket = $socket; - $this->remoteAddress = $remoteAddress; - } + public function __construct( + protected $socket, + protected string $remoteAddress) {} /** * Sends data on the connection. diff --git a/src/Protocols/Http/Chunk.php b/src/Protocols/Http/Chunk.php index f9a7394d7..5100ed2e0 100644 --- a/src/Protocols/Http/Chunk.php +++ b/src/Protocols/Http/Chunk.php @@ -27,30 +27,19 @@ */ class Chunk implements Stringable { - /** - * Chunk buffer. - * - * @var string - */ - protected string $buffer; /** * Chunk constructor. * - * @param string $buffer */ - public function __construct(string $buffer) - { - $this->buffer = $buffer; - } + public function __construct(protected string $buffer) {} /** * __toString * - * @return string */ public function __toString(): string { return dechex(strlen($this->buffer)) . "\r\n$this->buffer\r\n"; } -} \ No newline at end of file +} diff --git a/src/Protocols/Http/Request.php b/src/Protocols/Http/Request.php index 08b7d7a6d..548735828 100644 --- a/src/Protocols/Http/Request.php +++ b/src/Protocols/Http/Request.php @@ -78,13 +78,6 @@ class Request implements Stringable */ public array $properties = []; - /** - * Http buffer. - * - * @var string - */ - protected string $buffer; - /** * Request data. * @@ -116,12 +109,8 @@ class Request implements Stringable /** * Request constructor. * - * @param string $buffer */ - public function __construct(string $buffer) - { - $this->buffer = $buffer; - } + public function __construct(protected string $buffer) {} /** * Get query. diff --git a/src/Protocols/Http/ServerSentEvents.php b/src/Protocols/Http/ServerSentEvents.php index ad4a4ffa4..ca75fcac5 100644 --- a/src/Protocols/Http/ServerSentEvents.php +++ b/src/Protocols/Http/ServerSentEvents.php @@ -26,21 +26,11 @@ */ class ServerSentEvents implements Stringable { - /** - * Data. - * @var array - */ - protected array $data; - /** * ServerSentEvents constructor. * $data for example ['event'=>'ping', 'data' => 'some thing', 'id' => 1000, 'retry' => 5000] - * @param array $data */ - public function __construct(array $data) - { - $this->data = $data; - } + public function __construct(protected array $data) {} /** * __toString. From 4b720a7941da8a90f12d5d5dad6bbddef157433f Mon Sep 17 00:00:00 2001 From: Joanhey Date: Tue, 6 Aug 2024 22:11:50 +0200 Subject: [PATCH 2/4] Use string interpolation than is faster --- src/Protocols/Http/ServerSentEvents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocols/Http/ServerSentEvents.php b/src/Protocols/Http/ServerSentEvents.php index ca75fcac5..f200cd93a 100644 --- a/src/Protocols/Http/ServerSentEvents.php +++ b/src/Protocols/Http/ServerSentEvents.php @@ -56,6 +56,6 @@ public function __toString(): string if (isset($data['data'])) { $buffer .= 'data: ' . str_replace("\n", "\ndata: ", $data['data']) . "\n"; } - return $buffer . "\n"; + return "$buffer\n"; } } From 74525be38b5e53ea20b63fb259d929a90d54dd82 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Tue, 6 Aug 2024 22:32:12 +0200 Subject: [PATCH 3/4] Delete redundant comments --- src/Protocols/Http/Chunk.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Protocols/Http/Chunk.php b/src/Protocols/Http/Chunk.php index 5100ed2e0..2c7a2a8f8 100644 --- a/src/Protocols/Http/Chunk.php +++ b/src/Protocols/Http/Chunk.php @@ -28,16 +28,8 @@ class Chunk implements Stringable { - /** - * Chunk constructor. - * - */ public function __construct(protected string $buffer) {} - /** - * __toString - * - */ public function __toString(): string { return dechex(strlen($this->buffer)) . "\r\n$this->buffer\r\n"; From 1297111a60547b6c5ef355be6ce04a5b83a281e2 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Tue, 6 Aug 2024 23:37:07 +0200 Subject: [PATCH 4/4] Remove redundant comment --- src/Protocols/Http/ServerSentEvents.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Protocols/Http/ServerSentEvents.php b/src/Protocols/Http/ServerSentEvents.php index f200cd93a..6b70b10a8 100644 --- a/src/Protocols/Http/ServerSentEvents.php +++ b/src/Protocols/Http/ServerSentEvents.php @@ -32,11 +32,6 @@ class ServerSentEvents implements Stringable */ public function __construct(protected array $data) {} - /** - * __toString. - * - * @return string - */ public function __toString(): string { $buffer = '';