Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property promotion #1049

Merged
merged 4 commits into from
Aug 8, 2024
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
22 changes: 3 additions & 19 deletions src/Connection/UdpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 2 additions & 21 deletions src/Protocols/Http/Chunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,11 @@
*/
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";
}
}
}
13 changes: 1 addition & 12 deletions src/Protocols/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ class Request implements Stringable
*/
public array $properties = [];

/**
* Http buffer.
*
* @var string
*/
protected string $buffer;

/**
* Request data.
*
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 2 additions & 17 deletions src/Protocols/Http/ServerSentEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,12 @@
*/
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.
*
* @return string
*/
public function __toString(): string
{
$buffer = '';
Expand All @@ -66,6 +51,6 @@ public function __toString(): string
if (isset($data['data'])) {
$buffer .= 'data: ' . str_replace("\n", "\ndata: ", $data['data']) . "\n";
}
return $buffer . "\n";
return "$buffer\n";
}
}
Loading