diff --git a/.github/php-5.dockerfile b/.github/php-low.dockerfile similarity index 100% rename from .github/php-5.dockerfile rename to .github/php-low.dockerfile diff --git a/.github/prepare-test.sh b/.github/prepare-test.sh index 1960cf0..865098f 100755 --- a/.github/prepare-test.sh +++ b/.github/prepare-test.sh @@ -4,10 +4,10 @@ __DIR__=$(cd `dirname $0`; pwd) cd $__DIR__ -if [[ `expr $PHP_DOCKER_VERSION \< 7` -eq 0 ]]; then +if [[ `expr $PHP_DOCKER_VERSION \< 7.1` -eq 0 ]]; then export PHP_DOCKER_FILE="php.dockerfile" else - export PHP_DOCKER_FILE="php-5.dockerfile" + export PHP_DOCKER_FILE="php-low.dockerfile" fi containerName=$1 @@ -15,7 +15,9 @@ containerName=$1 docker-compose up -d $containerName \ && docker exec $containerName php -v \ && docker exec $containerName php -m \ -&& docker exec $containerName composer -V \ +&& docker exec $containerName php --ri curl +docker exec $containerName php --ri swoole +docker exec $containerName composer -V \ && docker ps -a n=0 diff --git a/.github/print-logs.php b/.github/print-logs.php new file mode 100644 index 0000000..c71e79c --- /dev/null +++ b/.github/print-logs.php @@ -0,0 +1,16 @@ +setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'php_unit_dedicate_assert' => ['target' => '5.6'], + 'array_syntax' => ['syntax' => 'short'], + 'array_indentation' => true, + 'binary_operator_spaces' => [ + 'operators' => [ + '=>' => 'align_single_space', + ], + ], + 'concat_space' => [ + 'spacing' => 'one', + ], + 'fopen_flags' => false, + 'protected_to_private' => false, + 'native_constant_invocation' => true, + 'single_quote' => true, + 'single_space_around_construct' => [ + 'constructs_followed_by_a_single_space' => [ + 'abstract', + 'as', + 'attribute', + 'break', + 'case', + 'catch', + 'class', + 'clone', + 'comment', + 'const', + 'const_import', + 'continue', + 'do', + 'echo', + 'else', + 'elseif', + 'enum', + 'extends', + 'final', + 'finally', + 'for', + 'foreach', + 'function', + 'function_import', + 'global', + 'goto', + 'if', + 'implements', + 'include', + 'include_once', + 'instanceof', + 'insteadof', + 'interface', + 'match', + 'named_argument', + // 'namespace', // 兼容性移除 + 'new', + 'open_tag_with_echo', + 'php_doc', + 'php_open', + 'print', + 'private', + 'protected', + 'public', + 'readonly', + 'require', + 'require_once', + 'return', + 'static', + 'switch', + 'throw', + 'trait', + 'try', + 'type_colon', + 'use', + 'use_lambda', + 'use_trait', + 'var', + 'while', + 'yield', + 'yield_from', + ], + ], + 'control_structure_continuation_position' => [ + 'position' => 'next_line', + ], + 'curly_braces_position' => [ + 'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end', + ], + 'no_superfluous_phpdoc_tags' => false, + 'single_line_comment_style' => false, + 'combine_nested_dirname' => false, + 'backtick_to_shell_exec' => false, + 'visibility_required' => false, + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude(__DIR__ . '/vendor') + ->in(__DIR__ . '/.github') + ->in(__DIR__ . '/src') + ->in(__DIR__ . '/examples') + ->in(__DIR__ . '/tests') + ->append([__FILE__]) + ) +; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index efd7022..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,44 +0,0 @@ -setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'php_unit_dedicate_assert' => ['target' => '5.6'], - 'array_syntax' => ['syntax' => 'short'], - 'array_indentation' => true, - 'binary_operator_spaces' => [ - 'operators' => [ - '=>' => 'align_single_space', - ], - ], - 'concat_space' => [ - 'spacing' => 'one', - ], - 'fopen_flags' => false, - 'protected_to_private' => false, - 'native_constant_invocation' => true, - 'single_quote' => true, - 'braces' => [ - 'position_after_control_structures' => 'next', - ], - 'no_superfluous_phpdoc_tags' => false, - 'single_line_comment_style' => false, - 'combine_nested_dirname' => false, - 'backtick_to_shell_exec' => false, - ]) - ->setRiskyAllowed(true) - ->setFinder( - PhpCsFixer\Finder::create() - ->exclude(__DIR__ . '/vendor') - ->in(__DIR__ . '/src') - ->in(__DIR__ . '/examples') - ->in(__DIR__ . '/tests') - ->append([__FILE__]) - ) -; diff --git a/composer.json b/composer.json index 0307b73..e9e0cbc 100644 --- a/composer.json +++ b/composer.json @@ -2,8 +2,8 @@ "name": "yurunsoft/yurun-http", "description": "YurunHttp 是开源的 PHP HTTP 类库,支持链式操作,简单易用。支持 Curl、Swoole,支持 Http、Http2、WebSocket!", "require": { - "php": ">=5.5.0", - "psr/http-message": "~1.0", + "php": ">=7.1", + "psr/http-message": "~1.0|~2.0", "psr/log": "~1.0|~2.0|~3.0" }, "require-dev": { diff --git a/examples/http2Client.php b/examples/http2Client.php index 5eb1d56..6a37902 100644 --- a/examples/http2Client.php +++ b/examples/http2Client.php @@ -23,7 +23,8 @@ { $response = $client->recv(); var_dump($response->body()); - } while ($response->success); + } + while ($response->success); }); // 客户端请求和响应获取 @@ -52,7 +53,8 @@ { ++$returnCount; } - } while ($returnCount < $count); + } + while ($returnCount < $count); $client->close(); }); diff --git a/examples/psr7Ex.php b/examples/psr7Ex.php index 4130495..5579f95 100644 --- a/examples/psr7Ex.php +++ b/examples/psr7Ex.php @@ -77,7 +77,7 @@ function test() ->withAttribute(Attributes::DOWNLOAD_SPEED, 30000) // 上传限速,单位:字节,仅Curl有效 ->withAttribute(Attributes::UPLOAD_SPEED, 30000) - ; + ; $response = YurunHttp::send($request); var_dump($response); } diff --git a/src/HttpRequest.php b/src/HttpRequest.php index 4908fea..f3fcd9f 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -63,7 +63,7 @@ class HttpRequest * * @var callable|null */ - public $retryCallback = null; + public $retryCallback; /** * 是否使用代理,默认false. @@ -175,7 +175,7 @@ class HttpRequest * * @var string */ - public $certPassword = null; + public $certPassword; /** * certType规定的私钥的加密类型,支持的密钥类型为"PEM"(默认值)、"DER"和"ENG". @@ -196,7 +196,7 @@ class HttpRequest * * @var string */ - public $keyPassword = null; + public $keyPassword; /** * 请求方法. @@ -217,7 +217,7 @@ class HttpRequest * * @var bool|null */ - public $connectionPool = null; + public $connectionPool; /** * 代理认证方式. @@ -654,7 +654,7 @@ public function ua($userAgent) */ public function retry($retry, $callback = null) { - $this->retry = $retry < 0 ? 0 : $retry; //至少请求1次,即重试0次 + $this->retry = $retry < 0 ? 0 : $retry; // 至少请求1次,即重试0次 $this->retryCallback = $callback; return $this; @@ -951,7 +951,7 @@ public function buildRequest($url = null, $requestBody = null, $method = null, $ ->withAttribute(Attributes::RETRY, $this->retry) ->withAttribute(Attributes::RETRY_CALLBACK, $this->retryCallback) ->withProtocolVersion($this->protocolVersion) - ; + ; foreach ($this->proxy as $name => $value) { $request = $request->withAttribute('proxy.' . $name, $value); diff --git a/src/YurunHttp.php b/src/YurunHttp.php index cda4a0c..f1ab98f 100644 --- a/src/YurunHttp.php +++ b/src/YurunHttp.php @@ -12,7 +12,7 @@ abstract class YurunHttp * * @var string|null */ - private static $defaultHandler = null; + private static $defaultHandler; /** * 属性. @@ -35,7 +35,7 @@ abstract class YurunHttp */ public static function setDefaultHandler($class) { - static::$defaultHandler = $class; + self::$defaultHandler = $class; } /** @@ -45,7 +45,7 @@ public static function setDefaultHandler($class) */ public static function getDefaultHandler() { - return static::$defaultHandler; + return self::$defaultHandler; } /** @@ -57,9 +57,9 @@ public static function getDefaultHandler() */ public static function getHandler($options = []) { - if (static::$defaultHandler) + if (self::$defaultHandler) { - $class = static::$defaultHandler; + $class = self::$defaultHandler; // @phpstan-ignore-next-line if (!is_subclass_of($class, IHandler::class)) { @@ -107,7 +107,7 @@ public static function send($request, $handlerClass = null, $options = []) $handler = new $handlerClass(); } } - foreach (static::$attributes as $name => $value) + foreach (self::$attributes as $name => $value) { if (null === $request->getAttribute($name)) { @@ -147,7 +147,7 @@ public static function websocket($request, $handlerClass = null, $options = []) { $handler = new $handlerClass(); } - foreach (static::$attributes as $name => $value) + foreach (self::$attributes as $name => $value) { if (null === $request->getAttribute($name)) { @@ -165,7 +165,7 @@ public static function websocket($request, $handlerClass = null, $options = []) */ public static function getAttributes() { - return static::$attributes; + return self::$attributes; } /** @@ -178,9 +178,9 @@ public static function getAttributes() */ public static function getAttribute($name, $default = null) { - if (\array_key_exists($name, static::$attributes)) + if (\array_key_exists($name, self::$attributes)) { - return static::$attributes[$name]; + return self::$attributes[$name]; } else { @@ -198,6 +198,6 @@ public static function getAttribute($name, $default = null) */ public static function setAttribute($name, $value) { - static::$attributes[$name] = $value; + self::$attributes[$name] = $value; } } diff --git a/src/YurunHttp/Cookie/CookieManager.php b/src/YurunHttp/Cookie/CookieManager.php index 003ff26..46cbf94 100644 --- a/src/YurunHttp/Cookie/CookieManager.php +++ b/src/YurunHttp/Cookie/CookieManager.php @@ -249,7 +249,7 @@ private function checkDomain($uriDomain, $cookieDomain) { return ($uriDomain === $cookieDomain) || (isset($cookieDomain[0]) && '.' === $cookieDomain[0] && substr($uriDomain, -\strlen($cookieDomain) - 1) === '.' . $cookieDomain) - ; + ; } /** @@ -293,7 +293,7 @@ private function checkPath($uriPath, $cookiePath) $path = \dirname($path); } } - if ('\\' === \DIRECTORY_SEPARATOR && false !== strpos($path, \DIRECTORY_SEPARATOR)) + if ('\\' === \DIRECTORY_SEPARATOR && str_contains($path, \DIRECTORY_SEPARATOR)) { $path = str_replace(\DIRECTORY_SEPARATOR, '/', $path); } diff --git a/src/YurunHttp/Handler/Curl.php b/src/YurunHttp/Handler/Curl.php index 1233fab..e8911fa 100644 --- a/src/YurunHttp/Handler/Curl.php +++ b/src/YurunHttp/Handler/Curl.php @@ -98,10 +98,10 @@ class Curl implements IHandler public function __construct($options = []) { $this->options = $options; - if (null === static::$defaultUA) + if (null === self::$defaultUA) { $version = curl_version(); - static::$defaultUA = sprintf('Mozilla/5.0 YurunHttp/%s Curl/%s', YurunHttp::VERSION, isset($version['version']) ? $version['version'] : 'unknown'); + self::$defaultUA = sprintf('Mozilla/5.0 YurunHttp/%s Curl/%s', YurunHttp::VERSION, isset($version['version']) ? $version['version'] : 'unknown'); } $this->initCookieManager(); } @@ -183,7 +183,7 @@ public function send(&$request) $retry = $request->getAttribute(Attributes::RETRY, 0); $retryCallback = $request->getAttribute(Attributes::RETRY_CALLBACK); $beginTime = microtime(true); - do + while (true) { // 请求方法 if ($isLocation && \in_array($statusCode, [301, 302, 303])) @@ -253,7 +253,8 @@ public function send(&$request) $this->cookieManager->gc(); $this->saveCookieJar(); break; - } while (true); + } + // 关闭保存至文件的句柄 if (null !== $saveFileFp) { @@ -293,11 +294,6 @@ private function buildCurlHandlerBase(&$request, $handler, &$headers = null, &$s { $options[\CURLOPT_RETURNTRANSFER] = true; } - // 保存cookie - if (!isset($options[\CURLOPT_COOKIEJAR])) - { - $options[\CURLOPT_COOKIEJAR] = 'php://memory'; - } // 允许复用连接 if (!isset($options[\CURLOPT_FORBID_REUSE])) { @@ -323,7 +319,6 @@ private function buildCurlHandlerBase(&$request, $handler, &$headers = null, &$s $this->parseSSL($request, $options); $this->parseProxy($request, $options); $this->parseHeaders($request, $options); - $this->parseCookies($request, $options); $this->parseNetwork($request, $options); curl_setopt_array($handler, $options); } @@ -386,6 +381,7 @@ private function buildCurlHandlerEx(&$request, $handler, $uri = null, $method = { $requestOptions[\CURLOPT_NOBODY] = true; } + $this->parseCookies($request, $requestOptions); curl_setopt_array($handler, $requestOptions); } @@ -459,7 +455,7 @@ private function parseHeaderOneRequest($headers) { $tmpHeaders = []; $count = \count($headers); - //从1开始,第0行包含了协议信息和状态信息,排除该行 + // 从1开始,第0行包含了协议信息和状态信息,排除该行 for ($i = 1; $i < $count; ++$i) { $line = trim($headers[$i]); @@ -610,7 +606,7 @@ private function parseHeaders(&$request, &$options) { if (!$request->hasHeader('User-Agent')) { - $request = $request->withHeader('User-Agent', $request->getAttribute(Attributes::USER_AGENT, static::$defaultUA)); + $request = $request->withHeader('User-Agent', $request->getAttribute(Attributes::USER_AGENT, self::$defaultUA)); } if (!$request->hasHeader('Connection') && $request->getProtocolVersion() >= 1.1) { @@ -677,7 +673,7 @@ private function parseNetwork(&$request, &$options) } else { - $userPwd = ''; + $userPwd = null; } // 连接超时 $options[\CURLOPT_CONNECTTIMEOUT_MS] = $request->getAttribute(Attributes::CONNECT_TIMEOUT, 30000); @@ -687,8 +683,11 @@ private function parseNetwork(&$request, &$options) $options[\CURLOPT_MAX_RECV_SPEED_LARGE] = $request->getAttribute(Attributes::DOWNLOAD_SPEED); // 上传限速 $options[\CURLOPT_MAX_SEND_SPEED_LARGE] = $request->getAttribute(Attributes::UPLOAD_SPEED); - // 连接中用到的用户名和密码 - $options[\CURLOPT_USERPWD] = $userPwd; + if (null !== $userPwd) + { + // 连接中用到的用户名和密码 + $options[\CURLOPT_USERPWD] = $userPwd; + } } /** @@ -751,7 +750,7 @@ public function coBatch($requests, $timeout = null) $running = null; $beginTime = microtime(true); // 执行批处理句柄 - do + while (true) { curl_multi_exec($mh, $running); if ($running > 0) @@ -766,7 +765,8 @@ public function coBatch($requests, $timeout = null) { break; } - } while (true); + } + foreach ($requests as $k => $request) { $handler = $curlHandlers[$k]; diff --git a/src/YurunHttp/Handler/Swoole.php b/src/YurunHttp/Handler/Swoole.php index 1caf32a..251a74e 100644 --- a/src/YurunHttp/Handler/Swoole.php +++ b/src/YurunHttp/Handler/Swoole.php @@ -43,13 +43,6 @@ class Swoole implements IHandler */ private $result; - /** - * 连接池键. - * - * @var string - */ - private $poolKey; - /** * 连接池是否启用. * @@ -77,9 +70,9 @@ class Swoole implements IHandler public function __construct($options = []) { $this->options = $options; - if (null === static::$defaultUA) + if (null === self::$defaultUA) { - static::$defaultUA = sprintf('Mozilla/5.0 YurunHttp/%s Swoole/%s', YurunHttp::VERSION, \defined('SWOOLE_VERSION') ? \SWOOLE_VERSION : 'unknown'); + self::$defaultUA = sprintf('Mozilla/5.0 YurunHttp/%s Swoole/%s', YurunHttp::VERSION, \defined('SWOOLE_VERSION') ? \SWOOLE_VERSION : 'unknown'); } $this->initCookieManager(); $this->httpConnectionManager = new SwooleHttpConnectionManager(); @@ -178,7 +171,7 @@ public function buildRequest($request, $connection, &$http2Request) } if (!$request->hasHeader('User-Agent')) { - $request = $request->withHeader('User-Agent', $request->getAttribute(Attributes::USER_AGENT, static::$defaultUA)); + $request = $request->withHeader('User-Agent', $request->getAttribute(Attributes::USER_AGENT, self::$defaultUA)); } $headers = []; foreach ($request->getHeaders() as $name => $value) @@ -269,7 +262,7 @@ public function sendDefer($request) $uri = $request->getUri(); try { - $this->poolKey = $poolKey = ConnectionPool::getKey($uri); + $poolKey = ConnectionPool::getKey($uri); if ($isHttp2) { /** @var \Swoole\Coroutine\Http2\Client $connection */ diff --git a/src/YurunHttp/Http/Psr7/AbstractMessage.php b/src/YurunHttp/Http/Psr7/AbstractMessage.php index d906ab6..3908694 100644 --- a/src/YurunHttp/Http/Psr7/AbstractMessage.php +++ b/src/YurunHttp/Http/Psr7/AbstractMessage.php @@ -59,7 +59,7 @@ public function __construct($body) * * @return string HTTP protocol version */ - public function getProtocolVersion() + public function getProtocolVersion(): string { return $this->protocolVersion; } @@ -78,7 +78,7 @@ public function getProtocolVersion() * * @return static */ - public function withProtocolVersion($version) + public function withProtocolVersion($version): MessageInterface { $self = clone $this; $self->protocolVersion = $version; @@ -111,7 +111,7 @@ public function withProtocolVersion($version) * key MUST be a header name, and each value MUST be an array of strings * for that header. */ - public function getHeaders() + public function getHeaders(): array { return $this->headers; } @@ -125,7 +125,7 @@ public function getHeaders() * name using a case-insensitive string comparison. Returns false if * no matching header name is found in the message. */ - public function hasHeader($name) + public function hasHeader($name): bool { $lowerName = strtolower($name); if (isset($this->headerNames[$lowerName])) @@ -151,7 +151,7 @@ public function hasHeader($name) * header. If the header does not appear in the message, this method MUST * return an empty array. */ - public function getHeader($name) + public function getHeader($name): array { $lowerName = strtolower($name); if (isset($this->headerNames[$lowerName])) @@ -188,7 +188,7 @@ public function getHeader($name) * concatenated together using a comma. If the header does not appear in * the message, this method MUST return an empty string. */ - public function getHeaderLine($name) + public function getHeaderLine($name): string { $lowerName = strtolower($name); if (isset($this->headerNames[$lowerName])) @@ -220,7 +220,7 @@ public function getHeaderLine($name) * * @throws \InvalidArgumentException for invalid header names or values */ - public function withHeader($name, $value) + public function withHeader($name, $value): MessageInterface { $self = clone $this; @@ -245,7 +245,7 @@ public function withHeader($name, $value) * * @throws \InvalidArgumentException for invalid header names or values */ - public function withAddedHeader($name, $value) + public function withAddedHeader($name, $value): MessageInterface { $self = clone $this; $lowerName = strtolower($name); @@ -292,7 +292,7 @@ public function withAddedHeader($name, $value) * * @return static */ - public function withoutHeader($name) + public function withoutHeader($name): MessageInterface { $self = clone $this; $lowerName = strtolower($name); @@ -313,7 +313,7 @@ public function withoutHeader($name) * * @return StreamInterface returns the body as a stream */ - public function getBody() + public function getBody(): StreamInterface { return $this->body; } @@ -333,7 +333,7 @@ public function getBody() * * @throws \InvalidArgumentException when the body is not valid */ - public function withBody(StreamInterface $body) + public function withBody(StreamInterface $body): MessageInterface { $self = clone $this; $self->body = $body; diff --git a/src/YurunHttp/Http/Psr7/Consts/MediaType.php b/src/YurunHttp/Http/Psr7/Consts/MediaType.php index 7516af3..a066f06 100644 --- a/src/YurunHttp/Http/Psr7/Consts/MediaType.php +++ b/src/YurunHttp/Http/Psr7/Consts/MediaType.php @@ -199,9 +199,9 @@ abstract class MediaType public static function getExt($contentType) { list($firstContentType) = explode(';', $contentType, 2); - if (isset(static::$extMap[$firstContentType])) + if (isset(self::$extMap[$firstContentType])) { - return static::$extMap[$firstContentType]; + return self::$extMap[$firstContentType]; } else { diff --git a/src/YurunHttp/Http/Psr7/Request.php b/src/YurunHttp/Http/Psr7/Request.php index 1e4447c..5a23db2 100644 --- a/src/YurunHttp/Http/Psr7/Request.php +++ b/src/YurunHttp/Http/Psr7/Request.php @@ -70,7 +70,7 @@ public function __construct($uri = null, array $headers = [], $body = '', $metho * * @return string */ - public function getRequestTarget() + public function getRequestTarget(): string { return null === $this->requestTarget ? (string) $this->uri : $this->requestTarget; } @@ -94,7 +94,7 @@ public function getRequestTarget() * * @return static */ - public function withRequestTarget($requestTarget) + public function withRequestTarget($requestTarget): RequestInterface { $self = clone $this; $self->requestTarget = $requestTarget; @@ -107,7 +107,7 @@ public function withRequestTarget($requestTarget) * * @return string returns the request method */ - public function getMethod() + public function getMethod(): string { return $this->method; } @@ -129,7 +129,7 @@ public function getMethod() * * @throws \InvalidArgumentException for invalid HTTP methods */ - public function withMethod($method) + public function withMethod($method): RequestInterface { $self = clone $this; $self->method = $method; @@ -147,7 +147,7 @@ public function withMethod($method) * @return UriInterface returns a UriInterface instance * representing the URI of the request */ - public function getUri() + public function getUri(): UriInterface { return $this->uri; } @@ -184,7 +184,7 @@ public function getUri() * * @return static */ - public function withUri(UriInterface $uri, $preserveHost = false) + public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface { $self = clone $this; $self->uri = $uri; diff --git a/src/YurunHttp/Http/Psr7/Response.php b/src/YurunHttp/Http/Psr7/Response.php index 146fe31..4cf2ef4 100644 --- a/src/YurunHttp/Http/Psr7/Response.php +++ b/src/YurunHttp/Http/Psr7/Response.php @@ -41,7 +41,7 @@ public function __construct($body = '', $statusCode = StatusCode::OK, $reasonPhr * * @return int status code */ - public function getStatusCode() + public function getStatusCode(): int { return $this->statusCode; } @@ -69,7 +69,7 @@ public function getStatusCode() * * @throws \InvalidArgumentException for invalid status code arguments */ - public function withStatus($code, $reasonPhrase = '') + public function withStatus($code, $reasonPhrase = ''): ResponseInterface { $self = clone $this; $self->statusCode = $code; @@ -99,7 +99,7 @@ public function withStatus($code, $reasonPhrase = '') * * @return string reason phrase; must return an empty string if none present */ - public function getReasonPhrase() + public function getReasonPhrase(): string { return $this->reasonPhrase; } diff --git a/src/YurunHttp/Http/Psr7/ServerRequest.php b/src/YurunHttp/Http/Psr7/ServerRequest.php index 1f06fe5..65babbb 100644 --- a/src/YurunHttp/Http/Psr7/ServerRequest.php +++ b/src/YurunHttp/Http/Psr7/ServerRequest.php @@ -87,7 +87,7 @@ public function __construct($uri = null, array $headers = [], $body = '', $metho * * @return array */ - public function getServerParams() + public function getServerParams(): array { return $this->server; } @@ -100,7 +100,7 @@ public function getServerParams() * * @return string */ - public function getServerParam($name, $default = null) + public function getServerParam($name, $default = null): string { return isset($this->server[$name]) ? $this->server[$name] : $default; } @@ -115,7 +115,7 @@ public function getServerParam($name, $default = null) * * @return array */ - public function getCookieParams() + public function getCookieParams(): array { return $this->cookies; } @@ -138,7 +138,7 @@ public function getCookieParams() * * @return static */ - public function withCookieParams(array $cookies) + public function withCookieParams(array $cookies): ServerRequestInterface { $self = clone $this; $self->cookies = $cookies; @@ -151,10 +151,8 @@ public function withCookieParams(array $cookies) * * @param string $name * @param mixed $default - * - * @return mixed */ - public function getCookie($name, $default = null) + public function getCookie(string $name, $default = null): string { return isset($this->cookies[$name]) ? $this->cookies[$name] : $default; } @@ -171,7 +169,7 @@ public function getCookie($name, $default = null) * * @return array */ - public function getQueryParams() + public function getQueryParams(): array { return $this->get; } @@ -199,7 +197,7 @@ public function getQueryParams() * * @return static */ - public function withQueryParams(array $query) + public function withQueryParams(array $query): ServerRequestInterface { $self = clone $this; $self->get = $query; @@ -219,7 +217,7 @@ public function withQueryParams(array $query) * @return UploadedFile[] an array tree of UploadedFileInterface instances; an empty * array MUST be returned if no data is present */ - public function getUploadedFiles() + public function getUploadedFiles(): array { return $this->files; } @@ -237,7 +235,7 @@ public function getUploadedFiles() * * @throws \InvalidArgumentException if an invalid structure is provided */ - public function withUploadedFiles(array $uploadedFiles) + public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface { $self = clone $this; @@ -334,7 +332,7 @@ public function getParsedBody() * @throws \InvalidArgumentException if an unsupported argument type is * provided */ - public function withParsedBody($data) + public function withParsedBody($data): ServerRequestInterface { $self = clone $this; $self->parsedBody = $data; @@ -353,7 +351,7 @@ public function withParsedBody($data) * * @return array attributes derived from the request */ - public function getAttributes() + public function getAttributes(): array { return $this->attributes; } @@ -405,7 +403,7 @@ public function getAttribute($name, $default = null) * * @return static */ - public function withAttribute($name, $value) + public function withAttribute($name, $value): ServerRequestInterface { $self = clone $this; $self->attributes[$name] = $value; @@ -429,7 +427,7 @@ public function withAttribute($name, $value) * * @return static */ - public function withoutAttribute($name) + public function withoutAttribute($name): ServerRequestInterface { $self = clone $this; if (\array_key_exists($name, $self->attributes)) diff --git a/src/YurunHttp/Http/Psr7/UploadedFile.php b/src/YurunHttp/Http/Psr7/UploadedFile.php index c4e7d58..34db06a 100644 --- a/src/YurunHttp/Http/Psr7/UploadedFile.php +++ b/src/YurunHttp/Http/Psr7/UploadedFile.php @@ -97,7 +97,7 @@ public function __construct($fileName, $mediaType, $tmpFileName, $size = null, $ * @throws \RuntimeException in cases when no stream is available or can be * created */ - public function getStream() + public function getStream(): StreamInterface { if (null === $this->stream) { @@ -143,7 +143,7 @@ public function getStream() * @throws \RuntimeException on any error during the move operation, or on * the second or subsequent call to the method */ - public function moveTo($targetPath) + public function moveTo($targetPath): void { if (!\is_string($targetPath)) { @@ -176,7 +176,7 @@ public function moveTo($targetPath) * * @return int|null the file size in bytes or null if unknown */ - public function getSize() + public function getSize(): ?int { return $this->size; } @@ -196,7 +196,7 @@ public function getSize() * * @return int one of PHP's UPLOAD_ERR_XXX constants */ - public function getError() + public function getError(): int { return $this->error; } @@ -214,7 +214,7 @@ public function getError() * @return string|null the filename sent by the client or null if none * was provided */ - public function getClientFilename() + public function getClientFilename(): ?string { return $this->fileName; } @@ -232,7 +232,7 @@ public function getClientFilename() * @return string|null the media type sent by the client or null if none * was provided */ - public function getClientMediaType() + public function getClientMediaType(): ?string { return $this->mediaType; } @@ -242,7 +242,7 @@ public function getClientMediaType() * * @return string */ - public function getTempFileName() + public function getTempFileName(): string { return $this->tmpFileName; } diff --git a/src/YurunHttp/Http/Psr7/Uri.php b/src/YurunHttp/Http/Psr7/Uri.php index b2711e9..aeb4135 100644 --- a/src/YurunHttp/Http/Psr7/Uri.php +++ b/src/YurunHttp/Http/Psr7/Uri.php @@ -199,7 +199,7 @@ public static function getDomain(UriInterface $uri) * * @return string the URI scheme */ - public function getScheme() + public function getScheme(): string { return $this->scheme; } @@ -223,7 +223,7 @@ public function getScheme() * * @return string the URI authority, in "[user-info@]host[:port]" format */ - public function getAuthority() + public function getAuthority(): string { $result = $this->host; if ('' !== $this->userInfo) @@ -253,7 +253,7 @@ public function getAuthority() * * @return string the URI user information, in "username[:password]" format */ - public function getUserInfo() + public function getUserInfo(): string { return $this->userInfo; } @@ -270,7 +270,7 @@ public function getUserInfo() * * @return string the URI host */ - public function getHost() + public function getHost(): string { return $this->host; } @@ -290,7 +290,7 @@ public function getHost() * * @return int|null the URI port */ - public function getPort() + public function getPort(): ?int { return $this->port; } @@ -321,7 +321,7 @@ public function getPort() * * @return string the URI path */ - public function getPath() + public function getPath(): string { return $this->path; } @@ -347,7 +347,7 @@ public function getPath() * * @return string the URI query string */ - public function getQuery() + public function getQuery(): string { return $this->query; } @@ -369,7 +369,7 @@ public function getQuery() * * @return string the URI fragment */ - public function getFragment() + public function getFragment(): string { return $this->fragment; } @@ -391,7 +391,7 @@ public function getFragment() * * @throws \InvalidArgumentException for invalid or unsupported schemes */ - public function withScheme($scheme) + public function withScheme($scheme): UriInterface { if (!\is_string($scheme)) { @@ -418,7 +418,7 @@ public function withScheme($scheme) * * @return static a new instance with the specified user information */ - public function withUserInfo($user, $password = null) + public function withUserInfo($user, $password = null): UriInterface { $self = clone $this; $self->userInfo = $user; @@ -444,7 +444,7 @@ public function withUserInfo($user, $password = null) * * @throws \InvalidArgumentException for invalid hostnames */ - public function withHost($host) + public function withHost($host): UriInterface { $self = clone $this; $self->host = $host; @@ -471,7 +471,7 @@ public function withHost($host) * * @throws \InvalidArgumentException for invalid ports */ - public function withPort($port) + public function withPort($port): UriInterface { $self = clone $this; $self->port = $port; @@ -503,7 +503,7 @@ public function withPort($port) * * @throws \InvalidArgumentException for invalid paths */ - public function withPath($path) + public function withPath($path): UriInterface { $self = clone $this; $self->path = $path; @@ -528,7 +528,7 @@ public function withPath($path) * * @throws \InvalidArgumentException for invalid query strings */ - public function withQuery($query) + public function withQuery($query): UriInterface { $self = clone $this; $self->query = $query; @@ -551,7 +551,7 @@ public function withQuery($query) * * @return static a new instance with the specified fragment */ - public function withFragment($fragment) + public function withFragment($fragment): UriInterface { $self = clone $this; $self->fragment = $fragment; @@ -583,7 +583,7 @@ public function withFragment($fragment) * * @return string */ - public function __toString() + public function __toString(): string { return static::makeUriString($this->host, $this->path, $this->query, $this->port, $this->scheme, $this->fragment, $this->userInfo); } diff --git a/src/YurunHttp/Stream/FileStream.php b/src/YurunHttp/Stream/FileStream.php index 9c47481..4fb68d4 100644 --- a/src/YurunHttp/Stream/FileStream.php +++ b/src/YurunHttp/Stream/FileStream.php @@ -79,7 +79,7 @@ public function __destruct() * * @return string */ - public function __toString() + public function __toString(): string { try { @@ -98,7 +98,7 @@ public function __toString() * * @return void */ - public function close() + public function close(): void { fclose($this->stream); $this->stream = null; @@ -124,7 +124,7 @@ public function detach() * * @return int|null returns the size in bytes if known, or null if unknown */ - public function getSize() + public function getSize(): ?int { $stat = fstat($this->stream); if (false === $stat) @@ -142,7 +142,7 @@ public function getSize() * * @throws \RuntimeException on error */ - public function tell() + public function tell(): int { $result = ftell($this->stream); if (false === $result) @@ -158,7 +158,7 @@ public function tell() * * @return bool */ - public function eof() + public function eof(): bool { return feof($this->stream); } @@ -168,7 +168,7 @@ public function eof() * * @return bool */ - public function isSeekable() + public function isSeekable(): bool { return (bool) $this->getMetadata('seekable'); } @@ -189,7 +189,7 @@ public function isSeekable() * * @throws \RuntimeException on failure */ - public function seek($offset, $whence = \SEEK_SET) + public function seek($offset, $whence = \SEEK_SET): void { if (-1 === fseek($this->stream, $offset, $whence)) { @@ -210,7 +210,7 @@ public function seek($offset, $whence = \SEEK_SET) * * @throws \RuntimeException on failure */ - public function rewind() + public function rewind(): void { if (!rewind($this->stream)) { @@ -223,7 +223,7 @@ public function rewind() * * @return bool */ - public function isWritable() + public function isWritable(): bool { return \in_array($this->mode, [ StreamMode::WRITE_CLEAN, @@ -245,7 +245,7 @@ public function isWritable() * * @throws \RuntimeException on failure */ - public function write($string) + public function write($string): int { $result = fwrite($this->stream, $string); if (false === $result) @@ -261,7 +261,7 @@ public function write($string) * * @return bool */ - public function isReadable() + public function isReadable(): bool { return \in_array($this->mode, [ StreamMode::READ_WRITE, @@ -284,7 +284,7 @@ public function isReadable() * * @throws \RuntimeException if an error occurs */ - public function read($length) + public function read($length): string { $result = fread($this->stream, $length); if (false === $result) @@ -303,7 +303,7 @@ public function read($length) * @throws \RuntimeException if unable to read or an error occurs while * reading */ - public function getContents() + public function getContents(): string { $result = stream_get_contents($this->stream); if (false === $result) @@ -355,7 +355,7 @@ public function getMetadata($key = null) * * @return UriInterface */ - public function getUri() + public function getUri(): UriInterface { return $this->uri; } diff --git a/src/YurunHttp/Stream/MemoryStream.php b/src/YurunHttp/Stream/MemoryStream.php index 22b2fd6..4f8604a 100644 --- a/src/YurunHttp/Stream/MemoryStream.php +++ b/src/YurunHttp/Stream/MemoryStream.php @@ -51,7 +51,7 @@ public function __construct($content = '') * * @return string */ - public function __toString() + public function __toString(): string { return $this->content; } @@ -61,7 +61,7 @@ public function __toString() * * @return void */ - public function close() + public function close(): void { $this->content = ''; $this->size = -1; @@ -84,7 +84,7 @@ public function detach() * * @return int|null returns the size in bytes if known, or null if unknown */ - public function getSize() + public function getSize(): ?int { return $this->size; } @@ -96,7 +96,7 @@ public function getSize() * * @throws \RuntimeException on error */ - public function tell() + public function tell(): int { return $this->position; } @@ -106,7 +106,7 @@ public function tell() * * @return bool */ - public function eof() + public function eof(): bool { return $this->position > $this->size; } @@ -116,7 +116,7 @@ public function eof() * * @return bool */ - public function isSeekable() + public function isSeekable(): bool { return true; } @@ -137,7 +137,7 @@ public function isSeekable() * * @throws \RuntimeException on failure */ - public function seek($offset, $whence = \SEEK_SET) + public function seek($offset, $whence = \SEEK_SET): void { switch ($whence) { @@ -170,7 +170,7 @@ public function seek($offset, $whence = \SEEK_SET) * * @throws \RuntimeException on failure */ - public function rewind() + public function rewind(): void { $this->position = 0; } @@ -180,7 +180,7 @@ public function rewind() * * @return bool */ - public function isWritable() + public function isWritable(): bool { return true; } @@ -194,7 +194,7 @@ public function isWritable() * * @throws \RuntimeException on failure */ - public function write($string) + public function write($string): int { $content = &$this->content; $position = &$this->position; @@ -211,7 +211,7 @@ public function write($string) * * @return bool */ - public function isReadable() + public function isReadable(): bool { return true; } @@ -228,7 +228,7 @@ public function isReadable() * * @throws \RuntimeException if an error occurs */ - public function read($length) + public function read($length): string { $position = &$this->position; $result = substr($this->content, $position, $length); @@ -245,7 +245,7 @@ public function read($length) * @throws \RuntimeException if unable to read or an error occurs while * reading */ - public function getContents() + public function getContents(): string { $position = &$this->position; if (0 === $position) @@ -268,7 +268,7 @@ public function getContents() * * @see http://php.net/manual/en/function.stream-get-meta-data.php * - * @param string $key specific metadata to retrieve + * @param string|null $key specific metadata to retrieve * * @return array|mixed|null Returns an associative array if no key is * provided. Returns a specific key value if a key is provided and the diff --git a/src/YurunHttp/Traits/THandler.php b/src/YurunHttp/Traits/THandler.php index 8200bf3..ec3309e 100644 --- a/src/YurunHttp/Traits/THandler.php +++ b/src/YurunHttp/Traits/THandler.php @@ -2,7 +2,6 @@ namespace Yurun\Util\YurunHttp\Traits; -use InvalidArgumentException; use Psr\Http\Message\UriInterface; use Yurun\Util\YurunHttp\Http\Psr7\Uri; @@ -23,7 +22,7 @@ public function parseRedirectLocation($location, $currentUri) { if (!isset($location[0])) { - throw new InvalidArgumentException(sprintf('Invalid $location: %s', $location)); + throw new \InvalidArgumentException(sprintf('Invalid $location: %s', $location)); } if ('/' === $location[0]) { @@ -35,7 +34,7 @@ public function parseRedirectLocation($location, $currentUri) $path = $currentUri->getPath(); if ('/' !== substr($path, -1, 1)) { - $path = $path . '/'; + $path .= '/'; } $path .= $location; $uri = $uri->withPath($path); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 8436467..68b37de 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -29,7 +29,7 @@ function testEnv($name, $default = null) for ($i = 0; $i < 10; ++$i) { $context = stream_context_create(['http' => ['timeout' => 1]]); - if ('YurunHttp' === @file_get_contents(testEnv('HTTP_SERVER_HOST', 'http://127.0.0.1:8899/'), false, $context)) + if ('YurunHttp' === @file_get_contents(testEnv('HTTP_SERVER_HOST', 'http://127.0.0.1:8898/'), false, $context)) { $serverStarted = true; break; diff --git a/tests/server/Http/WorkermanHttp.php b/tests/server/Http/WorkermanHttp.php index 837a338..e556dac 100644 --- a/tests/server/Http/WorkermanHttp.php +++ b/tests/server/Http/WorkermanHttp.php @@ -153,7 +153,7 @@ public static function input($recv_buffer, TcpConnection $connection) } elseif (preg_match("/\r\ncontent-length: ?(\d+)/i", $header, $match)) { - $length = $head_len + $match[1]; + $length = $head_len + (int) $match[1]; } else { @@ -256,6 +256,7 @@ public static function encode($response, TcpConnection $connection) unset($connection->__header); } + // @phpstan-ignore-next-line if (isset($response->file)) { $file = $response->file['file']; diff --git a/tests/server/Http/server.php b/tests/server/Http/server.php index 88c51a3..aeeb806 100644 --- a/tests/server/Http/server.php +++ b/tests/server/Http/server.php @@ -9,7 +9,7 @@ require_once __DIR__ . '/WorkermanHttp.php'; // #### http worker #### -$http_worker = new Worker('tcp://0.0.0.0:8899'); +$http_worker = new Worker('tcp://0.0.0.0:8898'); $http_worker->protocol = WorkermanHttp::class; diff --git a/tests/server/Http/start-server.sh b/tests/server/Http/start-server.sh index e2acbb1..188dcaa 100755 --- a/tests/server/Http/start-server.sh +++ b/tests/server/Http/start-server.sh @@ -4,4 +4,4 @@ __DIR__=$(cd `dirname $0`; pwd) ${__DIR__}/stop-server.sh -/usr/bin/env php $__DIR__/server.php start -d > /dev/null \ No newline at end of file +/usr/bin/env php $__DIR__/server.php start -d > ${__DIR__}/log.log \ No newline at end of file diff --git a/tests/server/Http2/start-server.sh b/tests/server/Http2/start-server.sh index b33b77d..1cbc227 100755 --- a/tests/server/Http2/start-server.sh +++ b/tests/server/Http2/start-server.sh @@ -10,4 +10,4 @@ else phpPath="/usr/bin/env php" fi -nohup $phpPath $__DIR__/http2-server.php > /dev/null 2>&1 & echo $! > "$__DIR__/server.pid" +nohup $phpPath $__DIR__/http2-server.php > ${__DIR__}/log.log 2>&1 & echo $! > "$__DIR__/server.pid" diff --git a/tests/server/WebSocket/start-server.sh b/tests/server/WebSocket/start-server.sh index a675a8e..d8404ce 100755 --- a/tests/server/WebSocket/start-server.sh +++ b/tests/server/WebSocket/start-server.sh @@ -10,4 +10,4 @@ else phpPath="/usr/bin/env php" fi -nohup $phpPath $__DIR__/ws-server.php > /dev/null 2>&1 & echo $! > "$__DIR__/server.pid" +nohup $phpPath $__DIR__/ws-server.php > ${__DIR__}/log.log 2>&1 & echo $! > "$__DIR__/server.pid" diff --git a/tests/unit/BaseTest.php b/tests/unit/BaseTest.php index 85e8879..0866a27 100644 --- a/tests/unit/BaseTest.php +++ b/tests/unit/BaseTest.php @@ -43,7 +43,7 @@ abstract class BaseTest extends TestCase public function __construct($name = null, array $data = [], $dataName = '') { parent::__construct($name, $data, $dataName); - $this->host = testEnv('HTTP_SERVER_HOST', 'http://127.0.0.1:8899/'); + $this->host = testEnv('HTTP_SERVER_HOST', 'http://127.0.0.1:8898/'); $this->wsHost = testEnv('WS_SERVER_HOST', 'ws://127.0.0.1:8900/'); $this->http2Host = testEnv('HTTP2_SERVER_HOST', 'http://127.0.0.1:8901/'); $this->wssHost = testEnv('WSS_SERVER_HOST', 'wss://127.0.0.1:8902/'); diff --git a/tests/unit/DefaultHandlerTest.php b/tests/unit/DefaultHandlerTest.php index c27b4b6..78ca411 100644 --- a/tests/unit/DefaultHandlerTest.php +++ b/tests/unit/DefaultHandlerTest.php @@ -10,7 +10,7 @@ class DefaultHandlerTest extends BaseTest { use TSwooleHandlerTest; - public function testCurl() + public function testCurl(): void { if (\extension_loaded('swoole')) { @@ -21,7 +21,7 @@ public function testCurl() $this->assertInstanceOf(\Yurun\Util\YurunHttp\Handler\Curl::class, YurunHttp::getHandler()); } - public function testSwoole() + public function testSwoole(): void { $this->call(function () { $this->assertNotEquals(-1, Coroutine::getuid()); @@ -31,7 +31,7 @@ public function testSwoole() }); } - public function testSetDefaultHandler() + public function testSetDefaultHandler(): void { YurunHttp::setDefaultHandler(null); $this->assertNull(YurunHttp::getDefaultHandler()); diff --git a/tests/unit/Http2/SwooleHttp2Test.php b/tests/unit/Http2/SwooleHttp2Test.php index f309b1e..56fef05 100644 --- a/tests/unit/Http2/SwooleHttp2Test.php +++ b/tests/unit/Http2/SwooleHttp2Test.php @@ -14,7 +14,7 @@ class SwooleHttp2Test extends BaseTest { use TSwooleHandlerTest; - public function testHttp2() + public function testHttp2(): void { $this->call(function () { $http = new HttpRequest(); @@ -43,7 +43,7 @@ public function testHttp2() }); } - public function testHttp2ByUrl() + public function testHttp2ByUrl(): void { $this->call(function () { $http = new HttpRequest(); @@ -70,7 +70,7 @@ public function testHttp2ByUrl() }); } - public function testMuiltCo() + public function testMuiltCo(): void { $this->call(function () { $uri = new Uri($this->http2Host); @@ -127,13 +127,14 @@ public function testMuiltCo() { ++$returnCount; } - } while ($returnCount < $count); + } + while ($returnCount < $count); $client->close(); }); } - public function testPipeline1() + public function testPipeline1(): void { $this->call(function () { $uri = new Uri($this->http2Host); @@ -177,7 +178,7 @@ public function testPipeline1() }); } - public function testPipeline2() + public function testPipeline2(): void { $this->call(function () { $uri = new Uri($this->http2Host); @@ -225,7 +226,7 @@ public function testPipeline2() * * @return void */ - public function testHttp2ResponseGetRequest() + public function testHttp2ResponseGetRequest(): void { $this->call(function () { $http = new HttpRequest(); @@ -251,7 +252,7 @@ public function testHttp2ResponseGetRequest() * * @return void */ - public function testHttp2ResponseGetRequest2() + public function testHttp2ResponseGetRequest2(): void { $this->call(function () { $uri = new Uri($this->http2Host); diff --git a/tests/unit/HttpRequestTest/CurlPoolTest.php b/tests/unit/HttpRequestTest/CurlPoolTest.php index aa36c60..89852f3 100644 --- a/tests/unit/HttpRequestTest/CurlPoolTest.php +++ b/tests/unit/HttpRequestTest/CurlPoolTest.php @@ -9,7 +9,7 @@ class CurlPoolTest extends BaseTest { - public function test() + public function test(): void { $this->call(function () { // 启用连接池 diff --git a/tests/unit/HttpRequestTest/HttpRequestTest.php b/tests/unit/HttpRequestTest/HttpRequestTest.php index fbfa957..e78a14a 100644 --- a/tests/unit/HttpRequestTest/HttpRequestTest.php +++ b/tests/unit/HttpRequestTest/HttpRequestTest.php @@ -20,7 +20,7 @@ class HttpRequestTest extends BaseTest * * @return void */ - public function testHelloWorld() + public function testHelloWorld(): void { $this->call(function () { $http = new HttpRequest(); @@ -35,7 +35,7 @@ public function testHelloWorld() * * @return void */ - public function testJson() + public function testJson(): void { $this->call(function () { $http = new HttpRequest(); @@ -51,7 +51,7 @@ public function testJson() * * @return void */ - public function testGetParams() + public function testGetParams(): void { $this->call(function () { $http = new HttpRequest(); @@ -69,7 +69,7 @@ public function testGetParams() * * @return void */ - public function testGetParams2() + public function testGetParams2(): void { $this->call(function () { $http = new HttpRequest(); @@ -90,11 +90,11 @@ public function testGetParams2() * * @return void */ - public function testPostParams() + public function testPostParams(): void { $this->call(function () { $http = new HttpRequest(); - $time = time(); + $time = (string) time(); $response = $http->post($this->host . '?a=info', [ 'time' => $time, ]); @@ -104,7 +104,7 @@ public function testPostParams() $this->assertEquals($time, isset($data['post']['time']) ? $data['post']['time'] : null); $http = new HttpRequest(); - $time = time(); + $time = (string) time(); $params = new \stdClass(); $params->time = $time; $this->assertResponse($response); @@ -119,7 +119,7 @@ public function testPostParams() * * @return void */ - public function testPutRequest() + public function testPutRequest(): void { $this->call(function () { $http = new HttpRequest(); @@ -135,7 +135,7 @@ public function testPutRequest() * * @return void */ - public function testCookieParams() + public function testCookieParams(): void { $this->call(function () { $http = new HttpRequest(); @@ -158,7 +158,7 @@ public function testCookieParams() * * @return void */ - public function testRequestHeaders() + public function testRequestHeaders(): void { $this->call(function () { $http = new HttpRequest(); @@ -188,7 +188,7 @@ public function testRequestHeaders() * * @return void */ - public function testResponseHeaders() + public function testResponseHeaders(): void { $this->call(function () { $http = new HttpRequest(); @@ -203,7 +203,7 @@ public function testResponseHeaders() * * @return void */ - public function testCookieManager() + public function testCookieManager(): void { $this->call(function () { $http = new HttpRequest(); @@ -250,7 +250,7 @@ public function testCookieManager() * * @return void */ - public function testAutoRedirect() + public function testAutoRedirect(): void { $this->call(function () { $http = new HttpRequest(); @@ -278,7 +278,7 @@ public function testAutoRedirect() * * @return void */ - public function testDisableAutoRedirect() + public function testDisableAutoRedirect(): void { $this->call(function () { $http = new HttpRequest(); @@ -295,7 +295,7 @@ public function testDisableAutoRedirect() * * @return void */ - public function testLimitMaxRedirects() + public function testLimitMaxRedirects(): void { $this->call(function () { $http = new HttpRequest(); @@ -311,7 +311,7 @@ public function testLimitMaxRedirects() * * @return void */ - public function testRedirectOther() + public function testRedirectOther(): void { $this->call(function () { $http = new HttpRequest(); @@ -327,7 +327,7 @@ public function testRedirectOther() /** * @return void */ - public function testRedirectCookie() + public function testRedirectCookie(): void { $this->call(function () { $http = new HttpRequest(); @@ -346,7 +346,7 @@ public function testRedirectCookie() * * @return void */ - public function testUploadSingle() + public function testUploadSingle(): void { $this->call(function () { $http = new HttpRequest(); @@ -372,7 +372,7 @@ public function testUploadSingle() * * @return void */ - public function testUploadMulti() + public function testUploadMulti(): void { $this->call(function () { $http = new HttpRequest(); @@ -408,7 +408,7 @@ public function testUploadMulti() * * @return void */ - public function testBody() + public function testBody(): void { $this->call(function () { $http = new HttpRequest(); @@ -435,7 +435,7 @@ public function testBody() * * @return void */ - public function testResponseGetRequest() + public function testResponseGetRequest(): void { $this->call(function () { $http = new HttpRequest(); @@ -447,7 +447,7 @@ public function testResponseGetRequest() }); } - public function test304() + public function test304(): void { $this->call(function () { /* @phpstan-ignore-next-line */ @@ -463,7 +463,7 @@ public function test304() }); } - public function testUriWithAuth() + public function testUriWithAuth(): void { $this->call(function () { $http = new HttpRequest(); @@ -479,7 +479,7 @@ public function testUriWithAuth() * * @return void */ - public function testDownload() + public function testDownload(): void { $this->call(function () { $http = new HttpRequest(); @@ -501,7 +501,7 @@ public function testDownload() * * @return void */ - public function testDownloadAutoExt() + public function testDownloadAutoExt(): void { $this->call(function () { $http = new HttpRequest(); @@ -523,7 +523,7 @@ public function testDownloadAutoExt() * * @return void */ - public function testDownloadWithRedirect() + public function testDownloadWithRedirect(): void { $this->call(function () { $http = new HttpRequest(); @@ -545,7 +545,7 @@ public function testDownloadWithRedirect() * * @return void */ - public function testCustomHost() + public function testCustomHost(): void { $this->call(function () { $http = new HttpRequest(); @@ -561,7 +561,7 @@ public function testCustomHost() * * @return void */ - public function testCoBatch() + public function testCoBatch(): void { $this->call(function () { $time = time(); @@ -644,7 +644,7 @@ public function testCoBatch() * * @return void */ - public function testCoBatchTimeout() + public function testCoBatchTimeout(): void { $this->call(function () { $result = Batch::run([ @@ -655,7 +655,7 @@ public function testCoBatchTimeout() }); } - public function testMemoryLeak() + public function testMemoryLeak(): void { $this->call(function () { $memorys = [1, 2, 3, 4, 5]; @@ -692,7 +692,7 @@ public function testMemoryLeak() }); } - public function testHead() + public function testHead(): void { $this->call(function () { $http = new HttpRequest(); @@ -706,7 +706,7 @@ public function testHead() * * @return void */ - public function testBug19() + public function testBug19(): void { $this->call(function () { $http = new HttpRequest(); @@ -723,7 +723,7 @@ public function testBug19() * * @return void */ - public function testCookieJar() + public function testCookieJar(): void { $this->call(function () { $http = new HttpRequest([ diff --git a/tests/unit/HttpRequestTest/SwoolePoolTest.php b/tests/unit/HttpRequestTest/SwoolePoolTest.php index 4104289..94588c7 100644 --- a/tests/unit/HttpRequestTest/SwoolePoolTest.php +++ b/tests/unit/HttpRequestTest/SwoolePoolTest.php @@ -12,7 +12,7 @@ class SwoolePoolTest extends BaseTest { use TSwooleHandlerTest; - public function test() + public function test(): void { $this->call(function () { // 启用连接池 diff --git a/tests/unit/WebSocketTest/WebSocketTest.php b/tests/unit/WebSocketTest/WebSocketTest.php index f60434a..e632737 100644 --- a/tests/unit/WebSocketTest/WebSocketTest.php +++ b/tests/unit/WebSocketTest/WebSocketTest.php @@ -10,7 +10,7 @@ class WebSocketTest extends BaseTest { use TSwooleHandlerTest; - public function testWebSocket() + public function testWebSocket(): void { $this->call(function () { $http = new HttpRequest(); @@ -33,7 +33,7 @@ public function testWebSocket() }); } - public function testWSS() + public function testWSS(): void { $this->call(function () { $http = new HttpRequest(); @@ -56,7 +56,7 @@ public function testWSS() }); } - public function testMemoryLeak() + public function testMemoryLeak(): void { $this->call(function () { $memorys = [1, 2, 3, 4, 5];