Explorar el Código

merged nested ifs together

Mark Magyar hace 2 años
padre
commit
be9f39cd47

+ 5 - 7
src/Connection/TcpConnection.php

@@ -939,13 +939,11 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
      */
     protected function checkBufferWillFull(): void
     {
-        if ($this->maxSendBufferSize <= strlen($this->sendBuffer)) {
-            if ($this->onBufferFull) {
-                try {
-                    ($this->onBufferFull)($this);
-                } catch (Throwable $e) {
-                    $this->error($e);
-                }
+        if ($this->maxSendBufferSize <= strlen($this->sendBuffer) && $this->onBufferFull) {
+            try {
+                ($this->onBufferFull)($this);
+            } catch (Throwable $e) {
+                $this->error($e);
             }
         }
     }

+ 3 - 5
src/Protocols/Http.php

@@ -145,11 +145,9 @@ class Http
             }
         }
 
-        if ($hasContentLength) {
-            if ($length > $connection->maxPackageSize) {
-                $connection->close("HTTP/1.1 413 Payload Too Large\r\n\r\n", true);
-                return 0;
-            }
+        if ($hasContentLength && $length > $connection->maxPackageSize) {
+            $connection->close("HTTP/1.1 413 Payload Too Large\r\n\r\n", true);
+            return 0;
         }
 
         if (!isset($buffer[512])) {

+ 2 - 4
src/Protocols/Http/Request.php

@@ -731,10 +731,8 @@ class Request
         if (isset($this->data['files'])) {
             clearstatcache();
             array_walk_recursive($this->data['files'], function ($value, $key) {
-                if ($key === 'tmp_name') {
-                    if (is_file($value)) {
-                        unlink($value);
-                    }
+                if ($key === 'tmp_name' && is_file($value)) {
+                    unlink($value);
                 }
             });
         }

+ 2 - 4
src/Protocols/Http/Response.php

@@ -414,10 +414,8 @@ class Response
             $head .= "Content-Disposition: attachment; filename=\"$baseName\"\r\n";
         }
 
-        if (!isset($headers['Last-Modified'])) {
-            if ($mtime = filemtime($file)) {
-                $head .= 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT' . "\r\n";
-            }
+        if (!isset($headers['Last-Modified']) && $mtime = filemtime($file)) {
+            $head .= 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT' . "\r\n";
         }
 
         return "$head\r\n";

+ 5 - 7
src/Protocols/Websocket.php

@@ -281,13 +281,11 @@ class Websocket
             }
             $connection->context->tmpWebsocketData .= $encodeBuffer;
             // Check buffer is full.
-            if ($connection->maxSendBufferSize <= strlen($connection->context->tmpWebsocketData)) {
-                if ($connection->onBufferFull) {
-                    try {
-                        ($connection->onBufferFull)($connection);
-                    } catch (Throwable $e) {
-                        Worker::stopAll(250, $e);
-                    }
+            if ($connection->maxSendBufferSize <= strlen($connection->context->tmpWebsocketData) && $connection->onBufferFull) {
+                try {
+                    ($connection->onBufferFull)($connection);
+                } catch (Throwable $e) {
+                    Worker::stopAll(250, $e);
                 }
             }
             // Return empty string.

+ 5 - 7
src/Protocols/Ws.php

@@ -277,13 +277,11 @@ class Ws
             }
             $connection->context->tmpWebsocketData = $connection->context->tmpWebsocketData . $frame;
             // Check buffer is full.
-            if ($connection->maxSendBufferSize <= strlen($connection->context->tmpWebsocketData)) {
-                if ($connection->onBufferFull) {
-                    try {
-                        ($connection->onBufferFull)($connection);
-                    } catch (Throwable $e) {
-                        Worker::stopAll(250, $e);
-                    }
+            if ($connection->maxSendBufferSize <= strlen($connection->context->tmpWebsocketData) && $connection->onBufferFull) {
+                try {
+                    ($connection->onBufferFull)($connection);
+                } catch (Throwable $e) {
+                    Worker::stopAll(250, $e);
                 }
             }
             return '';