Răsfoiți Sursa

Merge pull request #1049 from joanhey/property-promotion

Property promotion
walkor 1 an în urmă
părinte
comite
9e4ecd9723

+ 3 - 19
src/Connection/UdpConnection.php

@@ -46,30 +46,14 @@ 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.

+ 2 - 21
src/Protocols/Http/Chunk.php

@@ -27,30 +27,11 @@ use function strlen;
  */
 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";
     }
-}
+}

+ 1 - 12
src/Protocols/Http/Request.php

@@ -79,13 +79,6 @@ class Request implements Stringable
     public array $properties = [];
 
     /**
-     * Http buffer.
-     *
-     * @var string
-     */
-    protected string $buffer;
-
-    /**
      * Request data.
      *
      * @var array
@@ -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.

+ 2 - 17
src/Protocols/Http/ServerSentEvents.php

@@ -27,26 +27,11 @@ use function str_replace;
 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 = '';
@@ -66,6 +51,6 @@ class ServerSentEvents implements Stringable
         if (isset($data['data'])) {
             $buffer .= 'data: ' . str_replace("\n", "\ndata: ", $data['data']) . "\n";
         }
-        return $buffer . "\n";
+        return "$buffer\n";
     }
 }