Skip to content

Commit

Permalink
Merge pull request #1049 from joanhey/property-promotion
Browse files Browse the repository at this point in the history
Property promotion
  • Loading branch information
walkor authored Aug 8, 2024
2 parents fea0569 + 1297111 commit 9e4ecd9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 69 deletions.
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";
}
}

0 comments on commit 9e4ecd9

Please sign in to comment.