Skip to content

Commit

Permalink
chore: update to phpstan major version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Jan 6, 2025
1 parent 0d7f23d commit aab45d0
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 18 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 1 addition & 4 deletions lib/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ parameters:
message: "#^Left side of || is always false.$#"
count: 6
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
Expand Down
2 changes: 1 addition & 1 deletion tests/HTTP/Auth/AWSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/HTTP/Auth/DigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions tests/HTTP/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/HTTP/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testGetQueryParametersNoData(): void
}

/**
* @backupGlobals
* @backupGlobals enabled
*/
public function testCreateFromPHPRequest(): void
{
Expand Down

0 comments on commit aab45d0

Please sign in to comment.