Skip to content

Commit e4da42e

Browse files
authored
Modernize code (#14)
* Update phpstan dependency version * Remove unused code * Modernize code
1 parent 2dfe8f8 commit e4da42e

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^10.0 || ^11.0",
22-
"phpstan/phpstan": "^2",
22+
"phpstan/phpstan": "^2.1",
2323
"squizlabs/php_codesniffer": "^3.8",
2424
"slevomat/coding-standard": "~8.0"
2525
},

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false" failOnWarning="true">
33
<testsuites>
44
<testsuite name="Package Test Suite">
55
<directory suffix=".php">./tests/Unit/</directory>

src/Directive.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public function __construct(protected array $parameters = [])
2525
*/
2626
public function __toString(): string
2727
{
28-
return implode(', ', array_map(function ($key, $value) {
29-
return sprintf('%s="%s"', $key, $value);
30-
}, array_keys($this->parameters), $this->parameters));
28+
return implode(', ', array_map(
29+
fn(mixed $key, mixed $value): string => sprintf('%s="%s"', $key, $value),
30+
array_keys($this->parameters),
31+
$this->parameters,
32+
));
3133
}
3234
}

src/Tokens/HttpAuthentification.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function parse(): array
2222
throw new AuthentificationException('Failed to parse token.');
2323
}
2424

25-
if (strtolower(substr($value, 0, 5)) !== 'basic') {
25+
if (strtolower(substr((string) $value, 0, 5)) !== 'basic') {
2626
throw new AuthentificationException('Failed to parse token.');
2727
}
2828

29-
$data = explode(':', base64_decode(substr($value, 6)));
29+
$data = explode(':', base64_decode(substr((string) $value, 6)));
3030

3131
return [
3232
'username' => $this->getArrayValue($data, 0),

src/Tokens/HttpAuthorization.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ public function parse(): array
2222
throw new AuthentificationException('Failed to parse token.');
2323
}
2424

25-
if (strtolower(substr($value, 0, 6)) !== 'digest') {
25+
if (strtolower(substr((string) $value, 0, 6)) !== 'digest') {
2626
throw new AuthentificationException('Failed to parse token.');
2727
}
2828

29-
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $value, $matches, PREG_SET_ORDER);
29+
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', (string) $value, $matches, PREG_SET_ORDER);
3030

3131
$properties = [];
3232
foreach ($matches as $m) {
3333
$key = $m[1];
34-
$value = $m[2] ? $m[2] : $m[3];
34+
$value = $m[2] ?: $m[3];
3535
$properties[$key] = $value;
3636
}
3737

src/Tokens/PhpAuthDigest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public function parse(): array
2222
throw new AuthentificationException('Failed to parse token.');
2323
}
2424

25-
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $value, $matches, PREG_SET_ORDER);
25+
preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', (string) $value, $matches, PREG_SET_ORDER);
2626

2727
$properties = [];
2828
foreach ($matches as $m) {
2929
$key = $m[1];
30-
$value = $m[2] ? $m[2] : $m[3];
30+
$value = $m[2] ?: $m[3];
3131
$properties[$key] = $value;
3232
}
3333

src/Tokens/RedirectHttpAuthorization.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function parse(): array
2222
throw new AuthentificationException('Failed to parse token.');
2323
}
2424

25-
if (strtolower(substr($value, 0, 5)) !== 'basic') {
25+
if (strtolower(substr((string) $value, 0, 5)) !== 'basic') {
2626
throw new AuthentificationException('Failed to parse token.');
2727
}
2828

29-
list($username, $password) = explode(':', base64_decode(substr($value, 6)));
29+
[$username, $password] = explode(':', base64_decode(substr((string) $value, 6)));
3030

3131
return [
3232
'username' => $username,

src/Vaults/AbstractVault.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ public function setCredentials(string $username, string $password): self
137137
*/
138138
protected function denyAccess(?string $message = null): void
139139
{
140-
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
140+
$protocol = $_SERVER['SERVER_PROTOCOL'] ?: 'HTTP/1.1';
141141
$message = empty($message) ? '<strong>' . $protocol . ' 401 Unauthorized</strong>' : $message;
142142

143143
header($protocol . ' 401 Unauthorized');
144-
header('WWW-Authenticate: ' . $this->type()->value . ' ' . (string) $this->directive());
144+
header('WWW-Authenticate: ' . $this->type()->value . ' ' . $this->directive());
145145
exit($message);
146146
}
147147
}

0 commit comments

Comments
 (0)