diff --git a/composer.json b/composer.json index 69eb742..581f67f 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,9 @@ }, "require-dev" : { "friendsofphp/php-cs-fixer": "^3.66", - "phpstan/phpstan": "^1.12", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-strict-rules": "^1.6", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpstan/extension-installer": "^1.4", "phpunit/phpunit" : "^9.6" }, diff --git a/lib/Message.php b/lib/Message.php index ff8139f..9f36086 100644 --- a/lib/Message.php +++ b/lib/Message.php @@ -82,11 +82,8 @@ public function getBodyAsString(): string return ob_get_clean(); } - /** - * @var string|int|null $contentLength - */ $contentLength = $this->getHeader('Content-Length'); - if (null !== $contentLength && (is_int($contentLength) || ctype_digit($contentLength))) { + if (null !== $contentLength && ctype_digit($contentLength)) { return stream_get_contents($body, (int) $contentLength); } diff --git a/lib/Sapi.php b/lib/Sapi.php index 4383fda..e2c4b1a 100644 --- a/lib/Sapi.php +++ b/lib/Sapi.php @@ -86,7 +86,7 @@ public static function sendResponse(ResponseInterface $response): void $contentLength = $response->getHeader('Content-Length'); if (null !== $contentLength) { $output = fopen('php://output', 'wb'); - if (is_resource($body) && 'stream' == get_resource_type($body)) { + if (is_resource($body) && 'stream' === get_resource_type($body)) { // a workaround to make PHP more possible to use mmap based copy, see https://github.com/sabre-io/http/pull/119 $left = (int) $contentLength; // copy with 4MiB chunks diff --git a/phpstan.neon b/phpstan.neon index 509ce6a..024b14d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,5 @@ parameters: level: 6 - phpVersion: 70430 # PHP 7.4.30 ignoreErrors: - message: "#^Negated boolean expression is always true.$#" @@ -12,12 +11,8 @@ parameters: path: lib/Client.php - message: "#^Left side of || is always false.$#" - count: 6 + count: 19 path: lib/Client.php - - - message: "#^Else branch is unreachable because ternary operator condition is always true.$#" - count: 1 - path: lib/Auth/Digest.php - message: "#^Strict comparison using !== between '' and non-empty-string will always evaluate to true.$#" count: 1 diff --git a/tests/HTTP/Auth/AWSTest.php b/tests/HTTP/Auth/AWSTest.php index 2f1c1a9..88b18c6 100644 --- a/tests/HTTP/Auth/AWSTest.php +++ b/tests/HTTP/Auth/AWSTest.php @@ -200,7 +200,7 @@ public function test401(): void { $this->auth->requireLogin(); $test = preg_match('/^AWS$/', $this->response->getHeader('WWW-Authenticate'), $matches); - self::assertTrue(true == $test, 'The WWW-Authenticate response didn\'t match our pattern'); + self::assertTrue(1 === $test, 'The WWW-Authenticate response didn\'t match our pattern'); } /** diff --git a/tests/HTTP/Auth/DigestTest.php b/tests/HTTP/Auth/DigestTest.php index 78d5933..f5bc609 100644 --- a/tests/HTTP/Auth/DigestTest.php +++ b/tests/HTTP/Auth/DigestTest.php @@ -166,7 +166,7 @@ private function getServerTokens(int $qop = Digest::QOP_AUTH): array $test = preg_match('/Digest realm="'.self::REALM.'",qop="'.$qopstr.'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/', $this->response->getHeader('WWW-Authenticate'), $matches); - self::assertTrue(true == $test, 'The WWW-Authenticate response didn\'t match our pattern. We received: '.$this->response->getHeader('WWW-Authenticate')); + self::assertTrue(1 === $test, 'The WWW-Authenticate response didn\'t match our pattern. We received: '.$this->response->getHeader('WWW-Authenticate')); $nonce = $matches[1]; $opaque = $matches[2]; diff --git a/tests/HTTP/ClientTest.php b/tests/HTTP/ClientTest.php index 97345e2..d13ed1f 100644 --- a/tests/HTTP/ClientTest.php +++ b/tests/HTTP/ClientTest.php @@ -537,7 +537,7 @@ public function doRequest(RequestInterface $request): ResponseInterface // If nothing modified $response, we're using the default behavior. if (is_null($response)) { return parent::doRequest($request); - } else { /* @phpstan-ignore-line phpstan thinks Else branch is unreachable */ + } else { return $response; } } @@ -557,7 +557,7 @@ protected function curlStuff($curlHandle): array // If nothing modified $return, we're using the default behavior. if (is_null($return)) { return parent::curlStuff($curlHandle); - } else { /* @phpstan-ignore-line phpstan thinks Else branch is unreachable */ + } else { return $return; } } @@ -577,7 +577,7 @@ protected function curlExec($curlHandle): string // If nothing modified $return, we're using the default behavior. if (is_null($return)) { return parent::curlExec($curlHandle); - } else { /* @phpstan-ignore-line phpstan thinks Else branch is unreachable */ + } else { return $return; } } diff --git a/tests/HTTP/RequestTest.php b/tests/HTTP/RequestTest.php index 86322b3..848c286 100644 --- a/tests/HTTP/RequestTest.php +++ b/tests/HTTP/RequestTest.php @@ -35,7 +35,7 @@ public function testGetQueryParametersNoData(): void } /** - * @backupGlobals + * @backupGlobals enabled */ public function testCreateFromPHPRequest(): void {