diff --git a/composer.json b/composer.json index b68c2b6..eaf9ac5 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "require-dev": { "phpunit/phpunit": "^10.0 || ^11.0", - "phpstan/phpstan": "^2", + "phpstan/phpstan": "^2.1", "squizlabs/php_codesniffer": "^3.8", "slevomat/coding-standard": "~8.0" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e7c9e84..a4942e2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + ./tests/Unit/ diff --git a/src/Directive.php b/src/Directive.php index f9874c7..6b71faf 100644 --- a/src/Directive.php +++ b/src/Directive.php @@ -25,8 +25,10 @@ public function __construct(protected array $parameters = []) */ public function __toString(): string { - return implode(', ', array_map(function ($key, $value) { - return sprintf('%s="%s"', $key, $value); - }, array_keys($this->parameters), $this->parameters)); + return implode(', ', array_map( + fn(mixed $key, mixed $value): string => sprintf('%s="%s"', $key, $value), + array_keys($this->parameters), + $this->parameters, + )); } } diff --git a/src/Tokens/HttpAuthentification.php b/src/Tokens/HttpAuthentification.php index 54736d6..6f445f1 100644 --- a/src/Tokens/HttpAuthentification.php +++ b/src/Tokens/HttpAuthentification.php @@ -22,11 +22,11 @@ public function parse(): array throw new AuthentificationException('Failed to parse token.'); } - if (strtolower(substr($value, 0, 5)) !== 'basic') { + if (strtolower(substr((string) $value, 0, 5)) !== 'basic') { throw new AuthentificationException('Failed to parse token.'); } - $data = explode(':', base64_decode(substr($value, 6))); + $data = explode(':', base64_decode(substr((string) $value, 6))); return [ 'username' => $this->getArrayValue($data, 0), diff --git a/src/Tokens/HttpAuthorization.php b/src/Tokens/HttpAuthorization.php index db5595f..04a007d 100644 --- a/src/Tokens/HttpAuthorization.php +++ b/src/Tokens/HttpAuthorization.php @@ -22,16 +22,16 @@ public function parse(): array throw new AuthentificationException('Failed to parse token.'); } - if (strtolower(substr($value, 0, 6)) !== 'digest') { + if (strtolower(substr((string) $value, 0, 6)) !== 'digest') { throw new AuthentificationException('Failed to parse token.'); } - preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $value, $matches, PREG_SET_ORDER); + preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', (string) $value, $matches, PREG_SET_ORDER); $properties = []; foreach ($matches as $m) { $key = $m[1]; - $value = $m[2] ? $m[2] : $m[3]; + $value = $m[2] ?: $m[3]; $properties[$key] = $value; } diff --git a/src/Tokens/PhpAuthDigest.php b/src/Tokens/PhpAuthDigest.php index 5e55c1c..0164229 100644 --- a/src/Tokens/PhpAuthDigest.php +++ b/src/Tokens/PhpAuthDigest.php @@ -22,12 +22,12 @@ public function parse(): array throw new AuthentificationException('Failed to parse token.'); } - preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $value, $matches, PREG_SET_ORDER); + preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', (string) $value, $matches, PREG_SET_ORDER); $properties = []; foreach ($matches as $m) { $key = $m[1]; - $value = $m[2] ? $m[2] : $m[3]; + $value = $m[2] ?: $m[3]; $properties[$key] = $value; } diff --git a/src/Tokens/RedirectHttpAuthorization.php b/src/Tokens/RedirectHttpAuthorization.php index df06cb9..6e58080 100644 --- a/src/Tokens/RedirectHttpAuthorization.php +++ b/src/Tokens/RedirectHttpAuthorization.php @@ -22,11 +22,11 @@ public function parse(): array throw new AuthentificationException('Failed to parse token.'); } - if (strtolower(substr($value, 0, 5)) !== 'basic') { + if (strtolower(substr((string) $value, 0, 5)) !== 'basic') { throw new AuthentificationException('Failed to parse token.'); } - list($username, $password) = explode(':', base64_decode(substr($value, 6))); + [$username, $password] = explode(':', base64_decode(substr((string) $value, 6))); return [ 'username' => $username, diff --git a/src/Vaults/AbstractVault.php b/src/Vaults/AbstractVault.php index 25a28f1..e858fec 100644 --- a/src/Vaults/AbstractVault.php +++ b/src/Vaults/AbstractVault.php @@ -137,11 +137,11 @@ public function setCredentials(string $username, string $password): self */ protected function denyAccess(?string $message = null): void { - $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; + $protocol = $_SERVER['SERVER_PROTOCOL'] ?: 'HTTP/1.1'; $message = empty($message) ? '' . $protocol . ' 401 Unauthorized' : $message; header($protocol . ' 401 Unauthorized'); - header('WWW-Authenticate: ' . $this->type()->value . ' ' . (string) $this->directive()); + header('WWW-Authenticate: ' . $this->type()->value . ' ' . $this->directive()); exit($message); } }