Browse Source

format http

walkor 2 years ago
parent
commit
74acb3c08e

+ 82 - 58
src/Protocols/Http/Request.php

@@ -18,7 +18,30 @@ use Exception;
 use RuntimeException;
 use Workerman\Connection\TcpConnection;
 use Workerman\Protocols\Http;
-use Workerman\Worker;
+use function array_walk_recursive;
+use function bin2hex;
+use function clearstatcache;
+use function count;
+use function explode;
+use function file_put_contents;
+use function is_file;
+use function json_decode;
+use function ltrim;
+use function microtime;
+use function pack;
+use function parse_str;
+use function parse_url;
+use function preg_match;
+use function preg_replace;
+use function strlen;
+use function strpos;
+use function strstr;
+use function strtolower;
+use function substr;
+use function tempnam;
+use function trim;
+use function unlink;
+use function urlencode;
 
 /**
  * Class Request
@@ -134,7 +157,7 @@ class Request
         if (null === $name) {
             return $this->data['headers'];
         }
-        $name = \strtolower($name);
+        $name = strtolower($name);
         return $this->data['headers'][$name] ?? $default;
     }
 
@@ -149,7 +172,7 @@ class Request
     {
         if (!isset($this->data['cookie'])) {
             $this->data['cookie'] = [];
-            \parse_str(\preg_replace('/; ?/', '&', $this->header('cookie', '')), $this->data['cookie']);
+            parse_str(preg_replace('/; ?/', '&', $this->header('cookie', '')), $this->data['cookie']);
         }
         if ($name === null) {
             return $this->data['cookie'];
@@ -209,8 +232,8 @@ class Request
     public function host(bool $withoutPort = false): ?string
     {
         $host = $this->header('host');
-        if ($host && $withoutPort && $pos = \strpos($host, ':')) {
-            return \substr($host, 0, $pos);
+        if ($host && $withoutPort && $pos = strpos($host, ':')) {
+            return substr($host, 0, $pos);
         }
         return $host;
     }
@@ -236,7 +259,7 @@ class Request
     public function path(): string
     {
         if (!isset($this->data['path'])) {
-            $this->data['path'] = (string)\parse_url($this->uri(), PHP_URL_PATH);
+            $this->data['path'] = (string)parse_url($this->uri(), PHP_URL_PATH);
         }
         return $this->data['path'];
     }
@@ -249,7 +272,7 @@ class Request
     public function queryString(): string
     {
         if (!isset($this->data['query_string'])) {
-            $this->data['query_string'] = (string)\parse_url($this->uri(), PHP_URL_QUERY);
+            $this->data['query_string'] = (string)parse_url($this->uri(), PHP_URL_QUERY);
         }
         return $this->data['query_string'];
     }
@@ -258,6 +281,7 @@ class Request
      * Get session.
      *
      * @return Session
+     * @throws Exception
      */
     public function session(): Session
     {
@@ -326,7 +350,7 @@ class Request
     public function rawHead(): string
     {
         if (!isset($this->data['head'])) {
-            $this->data['head'] = \strstr($this->buffer, "\r\n\r\n", true);
+            $this->data['head'] = strstr($this->buffer, "\r\n\r\n", true);
         }
         return $this->data['head'];
     }
@@ -338,7 +362,7 @@ class Request
      */
     public function rawBody(): string
     {
-        return \substr($this->buffer, \strpos($this->buffer, "\r\n\r\n") + 4);
+        return substr($this->buffer, strpos($this->buffer, "\r\n\r\n") + 4);
     }
 
     /**
@@ -368,8 +392,8 @@ class Request
      */
     protected function parseHeadFirstLine()
     {
-        $firstLine = \strstr($this->buffer, "\r\n", true);
-        $tmp = \explode(' ', $firstLine, 3);
+        $firstLine = strstr($this->buffer, "\r\n", true);
+        $tmp = explode(' ', $firstLine, 3);
         $this->data['method'] = $tmp[0];
         $this->data['uri'] = $tmp[1] ?? '/';
     }
@@ -381,8 +405,8 @@ class Request
      */
     protected function parseProtocolVersion()
     {
-        $firstLine = \strstr($this->buffer, "\r\n", true);
-        $protocoVersion = substr(\strstr($firstLine, 'HTTP/'), 5);
+        $firstLine = strstr($this->buffer, "\r\n", true);
+        $protocoVersion = substr(strstr($firstLine, 'HTTP/'), 5);
         $this->data['protocolVersion'] = $protocoVersion ?: '1.0';
     }
 
@@ -396,24 +420,24 @@ class Request
         static $cache = [];
         $this->data['headers'] = [];
         $rawHead = $this->rawHead();
-        $endLinePosition = \strpos($rawHead, "\r\n");
+        $endLinePosition = strpos($rawHead, "\r\n");
         if ($endLinePosition === false) {
             return;
         }
-        $headBuffer = \substr($rawHead, $endLinePosition + 2);
+        $headBuffer = substr($rawHead, $endLinePosition + 2);
         $cacheable = static::$enableCache && !isset($headBuffer[4096]);
         if ($cacheable && isset($cache[$headBuffer])) {
             $this->data['headers'] = $cache[$headBuffer];
             return;
         }
-        $headData = \explode("\r\n", $headBuffer);
+        $headData = explode("\r\n", $headBuffer);
         foreach ($headData as $content) {
             if (str_contains($content, ':')) {
-                list($key, $value) = \explode(':', $content, 2);
-                $key = \strtolower($key);
-                $value = \ltrim($value);
+                list($key, $value) = explode(':', $content, 2);
+                $key = strtolower($key);
+                $value = ltrim($value);
             } else {
-                $key = \strtolower($content);
+                $key = strtolower($content);
                 $value = '';
             }
             if (isset($this->data['headers'][$key])) {
@@ -424,7 +448,7 @@ class Request
         }
         if ($cacheable) {
             $cache[$headBuffer] = $this->data['headers'];
-            if (\count($cache) > 128) {
+            if (count($cache) > 128) {
                 unset($cache[key($cache)]);
             }
         }
@@ -448,10 +472,10 @@ class Request
             $this->data['get'] = $cache[$queryString];
             return;
         }
-        \parse_str($queryString, $this->data['get']);
+        parse_str($queryString, $this->data['get']);
         if ($cacheable) {
             $cache[$queryString] = $this->data['get'];
-            if (\count($cache) > 256) {
+            if (count($cache) > 256) {
                 unset($cache[key($cache)]);
             }
         }
@@ -467,7 +491,7 @@ class Request
         static $cache = [];
         $this->data['post'] = $this->data['files'] = [];
         $contentType = $this->header('content-type', '');
-        if (\preg_match('/boundary="?(\S+)"?/', $contentType, $match)) {
+        if (preg_match('/boundary="?(\S+)"?/', $contentType, $match)) {
             $httpPostBoundary = '--' . $match[1];
             $this->parseUploadFiles($httpPostBoundary);
             return;
@@ -481,14 +505,14 @@ class Request
             $this->data['post'] = $cache[$bodyBuffer];
             return;
         }
-        if (\preg_match('/\bjson\b/i', $contentType)) {
-            $this->data['post'] = (array)\json_decode($bodyBuffer, true);
+        if (preg_match('/\bjson\b/i', $contentType)) {
+            $this->data['post'] = (array)json_decode($bodyBuffer, true);
         } else {
-            \parse_str($bodyBuffer, $this->data['post']);
+            parse_str($bodyBuffer, $this->data['post']);
         }
         if ($cacheable) {
             $cache[$bodyBuffer] = $this->data['post'];
-            if (\count($cache) > 256) {
+            if (count($cache) > 256) {
                 unset($cache[key($cache)]);
             }
         }
@@ -500,9 +524,9 @@ class Request
      * @param string $httpPostBoundary
      * @return void
      */
-    protected function parseUploadFiles($httpPostBoundary)
+    protected function parseUploadFiles(string $httpPostBoundary)
     {
-        $httpPostBoundary = \trim($httpPostBoundary, '"');
+        $httpPostBoundary = trim($httpPostBoundary, '"');
         $buffer = $this->buffer;
         $postEncodeString = '';
         $filesEncodeString = '';
@@ -519,7 +543,7 @@ class Request
 
         if ($filesEncodeString) {
             parse_str($filesEncodeString, $this->data['files']);
-            \array_walk_recursive($this->data['files'], function (&$value) use ($files) {
+            array_walk_recursive($this->data['files'], function (&$value) use ($files) {
                 $value = $files[$value];
             });
         }
@@ -539,41 +563,41 @@ class Request
     {
         $file = [];
         $boundary = "\r\n$boundary";
-        if (\strlen($this->buffer) < $sectionStartOffset) {
+        if (strlen($this->buffer) < $sectionStartOffset) {
             return 0;
         }
-        $sectionEndOffset = \strpos($this->buffer, $boundary, $sectionStartOffset);
+        $sectionEndOffset = strpos($this->buffer, $boundary, $sectionStartOffset);
         if (!$sectionEndOffset) {
             return 0;
         }
-        $contentLinesEndOffset = \strpos($this->buffer, "\r\n\r\n", $sectionStartOffset);
+        $contentLinesEndOffset = strpos($this->buffer, "\r\n\r\n", $sectionStartOffset);
         if (!$contentLinesEndOffset || $contentLinesEndOffset + 4 > $sectionEndOffset) {
             return 0;
         }
-        $contentLinesStr = \substr($this->buffer, $sectionStartOffset, $contentLinesEndOffset - $sectionStartOffset);
-        $contentLines = \explode("\r\n", trim($contentLinesStr . "\r\n"));
-        $boundaryValue = \substr($this->buffer, $contentLinesEndOffset + 4, $sectionEndOffset - $contentLinesEndOffset - 4);
+        $contentLinesStr = substr($this->buffer, $sectionStartOffset, $contentLinesEndOffset - $sectionStartOffset);
+        $contentLines = explode("\r\n", trim($contentLinesStr . "\r\n"));
+        $boundaryValue = substr($this->buffer, $contentLinesEndOffset + 4, $sectionEndOffset - $contentLinesEndOffset - 4);
         $uploadKey = false;
         foreach ($contentLines as $contentLine) {
-            if (!\strpos($contentLine, ': ')) {
+            if (!strpos($contentLine, ': ')) {
                 return 0;
             }
-            list($key, $value) = \explode(': ', $contentLine);
+            list($key, $value) = explode(': ', $contentLine);
             switch (strtolower($key)) {
                 case "content-disposition":
                     // Is file data.
-                    if (\preg_match('/name="(.*?)"; filename="(.*?)"/i', $value, $match)) {
+                    if (preg_match('/name="(.*?)"; filename="(.*?)"/i', $value, $match)) {
                         $error = 0;
                         $tmpFile = '';
-                        $size = \strlen($boundaryValue);
+                        $size = strlen($boundaryValue);
                         $tmpUploadDir = HTTP::uploadTmpDir();
                         if (!$tmpUploadDir) {
                             $error = UPLOAD_ERR_NO_TMP_DIR;
                         } else if ($boundaryValue === '') {
                             $error = UPLOAD_ERR_NO_FILE;
                         } else {
-                            $tmpFile = \tempnam($tmpUploadDir, 'workerman.upload.');
-                            if ($tmpFile === false || false == \file_put_contents($tmpFile, $boundaryValue)) {
+                            $tmpFile = tempnam($tmpUploadDir, 'workerman.upload.');
+                            if ($tmpFile === false || false == file_put_contents($tmpFile, $boundaryValue)) {
                                 $error = UPLOAD_ERR_CANT_WRITE;
                             }
                         }
@@ -590,24 +614,24 @@ class Request
                     } // Is post field.
                     else {
                         // Parse $POST.
-                        if (\preg_match('/name="(.*?)"$/', $value, $match)) {
+                        if (preg_match('/name="(.*?)"$/', $value, $match)) {
                             $k = $match[1];
-                            $postEncodeString .= \urlencode($k) . "=" . \urlencode($boundaryValue) . '&';
+                            $postEncodeString .= urlencode($k) . "=" . urlencode($boundaryValue) . '&';
                         }
-                        return $sectionEndOffset + \strlen($boundary) + 2;
+                        return $sectionEndOffset + strlen($boundary) + 2;
                     }
                 case "content-type":
-                    $file['type'] = \trim($value);
+                    $file['type'] = trim($value);
                     break;
             }
         }
         if ($uploadKey === false) {
             return 0;
         }
-        $filesEncodeStr .= \urlencode($uploadKey) . '=' . \count($files) . '&';
+        $filesEncodeStr .= urlencode($uploadKey) . '=' . count($files) . '&';
         $files[] = $file;
 
-        return $sectionEndOffset + \strlen($boundary) + 2;
+        return $sectionEndOffset + strlen($boundary) + 2;
     }
 
     /**
@@ -618,7 +642,7 @@ class Request
      */
     public static function createSessionId(): string
     {
-        return \bin2hex(\pack('d', \microtime(true)) . random_bytes(8));
+        return bin2hex(pack('d', microtime(true)) . random_bytes(8));
     }
 
     /**
@@ -653,7 +677,7 @@ class Request
      * @param mixed $value
      * @return void
      */
-    public function __set($name, $value)
+    public function __set(string $name, mixed $value)
     {
         $this->properties[$name] = $value;
     }
@@ -664,7 +688,7 @@ class Request
      * @param string $name
      * @return mixed|null
      */
-    public function __get($name)
+    public function __get(string $name)
     {
         return $this->properties[$name] ?? null;
     }
@@ -675,7 +699,7 @@ class Request
      * @param string $name
      * @return bool
      */
-    public function __isset($name)
+    public function __isset(string $name)
     {
         return isset($this->properties[$name]);
     }
@@ -686,7 +710,7 @@ class Request
      * @param string $name
      * @return void
      */
-    public function __unset($name)
+    public function __unset(string $name)
     {
         unset($this->properties[$name]);
     }
@@ -699,11 +723,11 @@ class Request
     public function __destruct()
     {
         if (isset($this->data['files'])) {
-            \clearstatcache();
-            \array_walk_recursive($this->data['files'], function ($value, $key) {
+            clearstatcache();
+            array_walk_recursive($this->data['files'], function ($value, $key) {
                 if ($key === 'tmp_name') {
-                    if (\is_file($value)) {
-                        \unlink($value);
+                    if (is_file($value)) {
+                        unlink($value);
                     }
                 }
             });

+ 37 - 22
src/Protocols/Http/Response.php

@@ -14,6 +14,21 @@
 
 namespace Workerman\Protocols\Http;
 
+use function array_merge_recursive;
+use function explode;
+use function file;
+use function filemtime;
+use function gmdate;
+use function is_array;
+use function is_file;
+use function pathinfo;
+use function preg_match;
+use function rawurlencode;
+use function strlen;
+use function substr;
+use const FILE_IGNORE_NEW_LINES;
+use const FILE_SKIP_EMPTY_LINES;
+
 /**
  * Class Response
  * @package Workerman\Protocols\Http
@@ -72,7 +87,7 @@ class Response
      * Phrases.
      *
      * @var array<int,string>
-     * 
+     *
      * @link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
      */
     const PHRASES = [
@@ -131,7 +146,7 @@ class Response
         429 => 'Too Many Requests', // RFC 6585
         431 => 'Request Header Fields Too Large', // RFC 6585
         451 => 'Unavailable For Legal Reasons', // RFC 7725
-        
+
         500 => 'Internal Server Error',
         501 => 'Not Implemented',
         502 => 'Bad Gateway',
@@ -163,8 +178,8 @@ class Response
      * @param string $body
      */
     public function __construct(
-        int   $status = 200,
-        array $headers = [],
+        int    $status = 200,
+        array  $headers = [],
         string $body = ''
     )
     {
@@ -206,7 +221,7 @@ class Response
      */
     public function withHeaders(array $headers): static
     {
-        $this->headers = \array_merge_recursive($this->headers, $headers);
+        $this->headers = array_merge_recursive($this->headers, $headers);
         return $this;
     }
 
@@ -321,7 +336,7 @@ class Response
      */
     public function withFile(string $file, int $offset = 0, int $length = 0): static
     {
-        if (!\is_file($file)) {
+        if (!is_file($file)) {
             return $this->withStatus(404)->withBody('<h3>404 Not Found</h3>');
         }
         $this->file = ['file' => $file, 'offset' => $offset, 'length' => $length];
@@ -341,9 +356,9 @@ class Response
      * @param bool $sameSite
      * @return $this
      */
-    public function cookie(string $name, string $value = '', int $maxAge = null, string $path = '', string $domain = '', bool $secure = false, bool $httpOnly = false, bool $sameSite  = false): static
+    public function cookie(string $name, string $value = '', int $maxAge = null, string $path = '', string $domain = '', bool $secure = false, bool $httpOnly = false, bool $sameSite = false): static
     {
-        $this->headers['Set-Cookie'][] = $name . '=' . \rawurlencode($value)
+        $this->headers['Set-Cookie'][] = $name . '=' . rawurlencode($value)
             . (empty($domain) ? '' : '; Domain=' . $domain)
             . ($maxAge === null ? '' : '; Max-Age=' . $maxAge)
             . (empty($path) ? '' : '; Path=' . $path)
@@ -363,13 +378,13 @@ class Response
     {
         $file = $fileInfo['file'];
         $reason = $this->reason ?: self::PHRASES[$this->status];
-        $head = "HTTP/{$this->version} {$this->status} $reason\r\n";
+        $head = "HTTP/$this->version $this->status $reason\r\n";
         $headers = $this->headers;
         if (!isset($headers['Server'])) {
             $head .= "Server: workerman\r\n";
         }
         foreach ($headers as $name => $value) {
-            if (\is_array($value)) {
+            if (is_array($value)) {
                 foreach ($value as $item) {
                     $head .= "$name: $item\r\n";
                 }
@@ -382,7 +397,7 @@ class Response
             $head .= "Connection: keep-alive\r\n";
         }
 
-        $fileInfo = \pathinfo($file);
+        $fileInfo = pathinfo($file);
         $extension = $fileInfo['extension'] ?? '';
         $baseName = $fileInfo['basename'] ?? 'unknown';
         if (!isset($headers['Content-Type'])) {
@@ -398,12 +413,12 @@ class Response
         }
 
         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 ($mtime = filemtime($file)) {
+                $head .= 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $mtime) . ' GMT' . "\r\n";
             }
         }
 
-        return "{$head}\r\n";
+        return "$head\r\n";
     }
 
     /**
@@ -418,18 +433,18 @@ class Response
         }
 
         $reason = $this->reason ?: self::PHRASES[$this->status] ?? '';
-        $bodyLen = \strlen($this->body);
+        $bodyLen = strlen($this->body);
         if (empty($this->headers)) {
-            return "HTTP/{$this->version} {$this->status} $reason\r\nServer: workerman\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $bodyLen\r\nConnection: keep-alive\r\n\r\n{$this->body}";
+            return "HTTP/$this->version $this->status $reason\r\nServer: workerman\r\nContent-Type: text/html;charset=utf-8\r\nContent-Length: $bodyLen\r\nConnection: keep-alive\r\n\r\n$this->body";
         }
 
-        $head = "HTTP/{$this->version} {$this->status} $reason\r\n";
+        $head = "HTTP/$this->version $this->status $reason\r\n";
         $headers = $this->headers;
         if (!isset($headers['Server'])) {
             $head .= "Server: workerman\r\n";
         }
         foreach ($headers as $name => $value) {
-            if (\is_array($value)) {
+            if (is_array($value)) {
                 foreach ($value as $item) {
                     $head .= "$name: $item\r\n";
                 }
@@ -451,7 +466,7 @@ class Response
         if (!isset($headers['Transfer-Encoding'])) {
             $head .= "Content-Length: $bodyLen\r\n\r\n";
         } else {
-            return "$head\r\n" . dechex($bodyLen) . "\r\n{$this->body}\r\n";
+            return "$head\r\n" . dechex($bodyLen) . "\r\n$this->body\r\n";
         }
 
         // The whole http package
@@ -466,12 +481,12 @@ class Response
     public static function initMimeTypeMap()
     {
         $mimeFile = __DIR__ . '/mime.types';
-        $items = \file($mimeFile, \FILE_IGNORE_NEW_LINES | \FILE_SKIP_EMPTY_LINES);
+        $items = file($mimeFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
         foreach ($items as $content) {
-            if (\preg_match("/\s*(\S+)\s+(\S.+)/", $content, $match)) {
+            if (preg_match("/\s*(\S+)\s+(\S.+)/", $content, $match)) {
                 $mimeType = $match[1];
                 $extensionVar = $match[2];
-                $extensionArray = \explode(' ', \substr($extensionVar, 0, -1));
+                $extensionArray = explode(' ', substr($extensionVar, 0, -1));
                 foreach ($extensionArray as $fileExtension) {
                     static::$mimeTypeMap[$fileExtension] = $mimeType;
                 }

+ 3 - 1
src/Protocols/Http/ServerSentEvents.php

@@ -14,6 +14,8 @@
 
 namespace Workerman\Protocols\Http;
 
+use function str_replace;
+
 /**
  * Class ServerSentEvents
  * @package Workerman\Protocols\Http
@@ -52,7 +54,7 @@ class ServerSentEvents
             $buffer .= "event: {$data['event']}\n";
         }
         if (isset($data['data'])) {
-            $buffer .= 'data: ' . \str_replace("\n", "\ndata: ", $data['data']) . "\n\n";
+            $buffer .= 'data: ' . str_replace("\n", "\ndata: ", $data['data']) . "\n\n";
         }
         if (isset($data['id'])) {
             $buffer .= "id: {$data['id']}\n";

+ 23 - 12
src/Protocols/Http/Session.php

@@ -15,9 +15,19 @@
 namespace Workerman\Protocols\Http;
 
 use Exception;
+use JetBrains\PhpStorm\ArrayShape;
 use RuntimeException;
 use Workerman\Protocols\Http\Session\FileSessionHandler;
 use Workerman\Protocols\Http\Session\SessionHandlerInterface;
+use function array_key_exists;
+use function ini_get;
+use function is_array;
+use function is_scalar;
+use function preg_match;
+use function random_int;
+use function serialize;
+use function session_get_cookie_params;
+use function unserialize;
 
 /**
  * Class Session
@@ -150,7 +160,7 @@ class Session
         }
         $this->sessionId = $sessionId;
         if ($data = static::$handler->read($sessionId)) {
-            $this->data = \unserialize($data);
+            $this->data = unserialize($data);
         }
     }
 
@@ -221,7 +231,7 @@ class Session
      */
     public function put(array|string $key, mixed $value = null)
     {
-        if (!\is_array($key)) {
+        if (!is_array($key)) {
             $this->set($key, $value);
             return;
         }
@@ -239,11 +249,11 @@ class Session
      */
     public function forget(array|string $name)
     {
-        if (\is_scalar($name)) {
+        if (is_scalar($name)) {
             $this->delete($name);
             return;
         }
-        if (\is_array($name)) {
+        if (is_array($name)) {
             foreach ($name as $key) {
                 unset($this->data[$key]);
             }
@@ -291,7 +301,7 @@ class Session
      */
     public function exists(string $name): bool
     {
-        return \array_key_exists($name, $this->data);
+        return array_key_exists($name, $this->data);
     }
 
     /**
@@ -305,7 +315,7 @@ class Session
             if (empty($this->data)) {
                 static::$handler->destroy($this->sessionId);
             } else {
-                static::$handler->write($this->sessionId, \serialize($this->data));
+                static::$handler->write($this->sessionId, serialize($this->data));
             }
         } elseif (static::$autoUpdateTimestamp) {
             static::refresh();
@@ -330,15 +340,15 @@ class Session
      */
     public static function init()
     {
-        if (($gcProbability = (int)\ini_get('session.gc_probability')) && ($gcDivisor = (int)\ini_get('session.gc_divisor'))) {
+        if (($gcProbability = (int)ini_get('session.gc_probability')) && ($gcDivisor = (int)ini_get('session.gc_divisor'))) {
             static::$gcProbability = [$gcProbability, $gcDivisor];
         }
 
-        if ($gcMaxLifeTime = \ini_get('session.gc_maxlifetime')) {
+        if ($gcMaxLifeTime = ini_get('session.gc_maxlifetime')) {
             self::$lifetime = (int)$gcMaxLifeTime;
         }
 
-        $sessionCookieParams = \session_get_cookie_params();
+        $sessionCookieParams = session_get_cookie_params();
         static::$cookieLifetime = $sessionCookieParams['lifetime'];
         static::$cookiePath = $sessionCookieParams['path'];
         static::$domain = $sessionCookieParams['domain'];
@@ -369,6 +379,7 @@ class Session
      *
      * @return array
      */
+    #[ArrayShape(['lifetime' => "int", 'path' => "string", 'domain' => "string", 'secure' => "bool", 'httponly' => "bool", 'samesite' => "string"])]
     public static function getCookieParams(): array
     {
         return [
@@ -414,7 +425,7 @@ class Session
     public function __destruct()
     {
         $this->save();
-        if (\random_int(1, static::$gcProbability[1]) <= static::$gcProbability[0]) {
+        if (random_int(1, static::$gcProbability[1]) <= static::$gcProbability[0]) {
             $this->gc();
         }
     }
@@ -424,9 +435,9 @@ class Session
      *
      * @param string $sessionId
      */
-    protected static function checkSessionId($sessionId)
+    protected static function checkSessionId(string $sessionId)
     {
-        if (!\preg_match('/^[a-zA-Z0-9]+$/', $sessionId)) {
+        if (!preg_match('/^[a-zA-Z0-9]+$/', $sessionId)) {
             throw new RuntimeException("session_id $sessionId is invalid");
         }
     }