Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"sabre/uri" : "^2.3 || ^3.0"
},
"require-dev" : {
"friendsofphp/php-cs-fixer": "^3.91",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.6",
"friendsofphp/php-cs-fixer": "^3.95",
"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)) {
Comment on lines 88 to +86
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHeader can only return string or null. So is_int() is useless code.

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
18 changes: 18 additions & 0 deletions phpstan-ignore-by-php-version.neon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

$includes = [];
if (PHP_VERSION_ID >= 80000) {
$includes[] = __DIR__.'/phpstan-ignore-php8.neon';
} else {
$includes[] = __DIR__.'/phpstan-ignore-php74.neon';
}

$config = [];
$config['includes'] = $includes;

// overrides config.platform.php in composer.json
$config['parameters']['phpVersion'] = PHP_VERSION_ID;

return $config;
6 changes: 6 additions & 0 deletions phpstan-ignore-php74.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Left side of || is always false.$#"
count: 10
path: lib/Client.php
6 changes: 6 additions & 0 deletions phpstan-ignore-php8.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Left side of || is always false.$#"
count: 23
path: lib/Client.php
20 changes: 3 additions & 17 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
includes:
- phpstan-ignore-by-php-version.neon.php

parameters:
level: 6
phpVersion: 70430 # PHP 7.4.30
ignoreErrors:
-
message: "#^Negated boolean expression is always true.$#"
count: 1
path: lib/Client.php
-
message: "#^If condition is always false.$#"
count: 3
path: lib/Client.php
-
message: "#^Left side of || is always false.$#"
count: 6
path: lib/Client.php
-
Comment thread
phil-davis marked this conversation as resolved.
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');
Comment on lines 202 to +203
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preg_match returns (int) 1 not (bool) true.

}

/**
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'));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preg_match returns (int) 1 not (bool) true.


$nonce = $matches[1];
$opaque = $matches[2];
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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backupGlobals should explicitly have the keyword "enabled"

Copy link
Copy Markdown
Member

@staabm staabm Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this annotation work as expected in phpunit without the suffix? If not we might just drop it

*/
public function testCreateFromPHPRequest(): void
{
Expand Down
Loading