Skip to content
Closed
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
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
"sabre/uri" : "^2.3"
},
"require-dev" : {
"friendsofphp/php-cs-fixer": "^3.87",
"phpstan/phpstan": "^1.12",
"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"
},
"suggest" : {
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
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
18 changes: 8 additions & 10 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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.$#"
message: "#^Strict comparison using !== between '' and non-empty-string will always evaluate to true.$#"
count: 1
path: lib/Client.php
path: lib/Auth/Digest.php
-
message: "#^If condition is always false.$#"
count: 3
path: lib/Client.php
-
message: "#^Left side of || is always false.$#"
count: 2
path: lib/Client.php
message: "#^Casting to string something that's already string.$#"
count: 1
path: lib/Sapi.php
-
message: "#^Strict comparison using === between null and array<string, mixed> will always evaluate to false.$#"
count: 1
Expand Down
32 changes: 16 additions & 16 deletions tests/HTTP/Auth/AWSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public function testNoHeader(): void
$this->request->setMethod('GET');
$result = $this->auth->init();

$this->assertFalse($result, 'No AWS Authorization header was supplied, so we should have gotten false');
$this->assertEquals(AWS::ERR_NOAWSHEADER, $this->auth->errorCode);
self::assertFalse($result, 'No AWS Authorization header was supplied, so we should have gotten false');
self::assertEquals(AWS::ERR_NOAWSHEADER, $this->auth->errorCode);
}

public function testInvalidAuthorizationHeader(): void
{
$this->request->setMethod('GET');
$this->request->setHeader('Authorization', 'Invalid Auth Header');

$this->assertFalse($this->auth->init(), 'The Invalid AWS authorization header');
self::assertFalse($this->auth->init(), 'The Invalid AWS authorization header');
}

public function testIncorrectContentMD5(): void
Expand All @@ -56,8 +56,8 @@ public function testIncorrectContentMD5(): void
$this->auth->init();
$result = $this->auth->validate($secretKey);

$this->assertFalse($result);
$this->assertEquals(AWS::ERR_MD5CHECKSUMWRONG, $this->auth->errorCode);
self::assertFalse($result);
self::assertEquals(AWS::ERR_MD5CHECKSUMWRONG, $this->auth->errorCode);
}

public function testNoDate(): void
Expand All @@ -78,8 +78,8 @@ public function testNoDate(): void
$this->auth->init();
$result = $this->auth->validate($secretKey);

$this->assertFalse($result);
$this->assertEquals(AWS::ERR_INVALIDDATEFORMAT, $this->auth->errorCode);
self::assertFalse($result);
self::assertEquals(AWS::ERR_INVALIDDATEFORMAT, $this->auth->errorCode);
}

public function testFutureDate(): void
Expand All @@ -105,8 +105,8 @@ public function testFutureDate(): void
$this->auth->init();
$result = $this->auth->validate($secretKey);

$this->assertFalse($result);
$this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode);
self::assertFalse($result);
self::assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode);
}

public function testPastDate(): void
Expand All @@ -132,8 +132,8 @@ public function testPastDate(): void
$this->auth->init();
$result = $this->auth->validate($secretKey);

$this->assertFalse($result);
$this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode);
self::assertFalse($result);
self::assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode);
}

public function testIncorrectSignature(): void
Expand All @@ -160,8 +160,8 @@ public function testIncorrectSignature(): void
$this->auth->init();
$result = $this->auth->validate($secretKey);

$this->assertFalse($result);
$this->assertEquals(AWS::ERR_INVALIDSIGNATURE, $this->auth->errorCode);
self::assertFalse($result);
self::assertEquals(AWS::ERR_INVALIDSIGNATURE, $this->auth->errorCode);
}

public function testValidRequest(): void
Expand Down Expand Up @@ -192,15 +192,15 @@ public function testValidRequest(): void
$this->auth->init();
$result = $this->auth->validate($secretKey);

$this->assertTrue($result, 'Signature did not validate, got errorcode '.$this->auth->errorCode);
$this->assertEquals($accessKey, $this->auth->getAccessKey());
self::assertTrue($result, 'Signature did not validate, got errorcode '.$this->auth->errorCode);
self::assertEquals($accessKey, $this->auth->getAccessKey());
}

public function test401(): void
{
$this->auth->requireLogin();
$test = preg_match('/^AWS$/', $this->response->getHeader('WWW-Authenticate'), $matches);
$this->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
12 changes: 6 additions & 6 deletions tests/HTTP/Auth/BasicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testGetCredentials(): void

$basic = new Basic('Dagger', $request, new Response());

$this->assertEquals([
self::assertEquals([
'user',
'pass:bla',
], $basic->getCredentials());
Expand All @@ -31,15 +31,15 @@ public function testGetInvalidCredentialsColonMissing(): void

$basic = new Basic('Dagger', $request, new Response());

$this->assertNull($basic->getCredentials());
self::assertNull($basic->getCredentials());
}

public function testGetCredentialsNoHeader(): void
{
$request = new Request('GET', '/', []);
$basic = new Basic('Dagger', $request, new Response());

$this->assertNull($basic->getCredentials());
self::assertNull($basic->getCredentials());
}

public function testGetCredentialsNotBasic(): void
Expand All @@ -49,7 +49,7 @@ public function testGetCredentialsNotBasic(): void
]);
$basic = new Basic('Dagger', $request, new Response());

$this->assertNull($basic->getCredentials());
self::assertNull($basic->getCredentials());
}

public function testRequireLogin(): void
Expand All @@ -61,7 +61,7 @@ public function testRequireLogin(): void

$basic->requireLogin();

$this->assertEquals('Basic realm="Dagger", charset="UTF-8"', $response->getHeader('WWW-Authenticate'));
$this->assertEquals(401, $response->getStatus());
self::assertEquals('Basic realm="Dagger", charset="UTF-8"', $response->getHeader('WWW-Authenticate'));
self::assertEquals(401, $response->getStatus());
}
}
10 changes: 5 additions & 5 deletions tests/HTTP/Auth/BearerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testGetToken(): void

$bearer = new Bearer('Dagger', $request, new Response());

$this->assertEquals(
self::assertEquals(
'12345',
$bearer->getToken()
);
Expand All @@ -28,7 +28,7 @@ public function testGetCredentialsNoHeader(): void
$request = new Request('GET', '/', []);
$bearer = new Bearer('Dagger', $request, new Response());

$this->assertNull($bearer->getToken());
self::assertNull($bearer->getToken());
}

public function testGetCredentialsNotBearer(): void
Expand All @@ -38,7 +38,7 @@ public function testGetCredentialsNotBearer(): void
]);
$bearer = new Bearer('Dagger', $request, new Response());

$this->assertNull($bearer->getToken());
self::assertNull($bearer->getToken());
}

public function testRequireLogin(): void
Expand All @@ -49,7 +49,7 @@ public function testRequireLogin(): void

$bearer->requireLogin();

$this->assertEquals('Bearer realm="Dagger"', $response->getHeader('WWW-Authenticate'));
$this->assertEquals(401, $response->getStatus());
self::assertEquals('Bearer realm="Dagger"', $response->getHeader('WWW-Authenticate'));
self::assertEquals(401, $response->getStatus());
}
}
18 changes: 9 additions & 9 deletions tests/HTTP/Auth/DigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function testDigest(): void

$this->auth->init();

$this->assertEquals($username, $this->auth->getUsername());
$this->assertEquals(self::REALM, $this->auth->getRealm());
$this->assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1');
$this->assertTrue($this->auth->validatePassword($password), 'Authentication is deemed invalid through validatePassword');
self::assertEquals($username, $this->auth->getUsername());
self::assertEquals(self::REALM, $this->auth->getRealm());
self::assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1');
self::assertTrue($this->auth->validatePassword($password), 'Authentication is deemed invalid through validatePassword');
}

public function testInvalidDigest(): void
Expand All @@ -79,7 +79,7 @@ public function testInvalidDigest(): void

$this->auth->init();

$this->assertFalse($this->auth->validateA1(md5($username.':'.self::REALM.':'.($password.'randomness'))), 'Authentication is deemed invalid through validateA1');
self::assertFalse($this->auth->validateA1(md5($username.':'.self::REALM.':'.($password.'randomness'))), 'Authentication is deemed invalid through validateA1');
}

public function testInvalidDigest2(): void
Expand All @@ -88,7 +88,7 @@ public function testInvalidDigest2(): void
$this->request->setHeader('Authorization', 'basic blablabla');

$this->auth->init();
$this->assertFalse($this->auth->validateA1(md5('user:realm:password')));
self::assertFalse($this->auth->validateA1(md5('user:realm:password')));
}

public function testDigestAuthInt(): void
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testDigestAuthInt(): void

$this->auth->init();

$this->assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1');
self::assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1');
}

public function testDigestAuthBoth(): void
Expand Down Expand Up @@ -144,7 +144,7 @@ public function testDigestAuthBoth(): void

$this->auth->init();

$this->assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1');
self::assertTrue($this->auth->validateA1(md5($username.':'.self::REALM.':'.$password)), 'Authentication is deemed invalid through validateA1');
}

/**
Expand All @@ -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);

$this->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
Loading
Loading