Skip to content
Prev Previous commit
Next Next commit
[master] fix more phpstan errors
  • Loading branch information
annadamm-check24 committed Mar 4, 2024
commit 3ba625f245f2b916141e80aaadb57efe71a3cb0b
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"scripts": {
"check" : [
"@cs-check",
"@phpstan",
"@test"
],
"cs-check" : "phpcs --parallel=50",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
tmpDir: data/phpstan
cache:
nodesByStringCountMax: 0
level: 6
level: 7
fileExtensions:
- php
paths:
Expand Down
2 changes: 2 additions & 0 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function createRequest(
$timestamp += $this->localtimeOffset;
}

/** @var array{host: string, path?: string, query?: string, scheme: string, port?: int} $parsed */
$parsed = parse_url($uri);
$host = $parsed['host'];
$resource = $parsed['path'] ?? '';
Expand Down Expand Up @@ -191,6 +192,7 @@ public function createBewit(
$timestamp += $this->localtimeOffset;
}

/** @var array{host: string, path?: string, query?: string, scheme: string, port?: int} $parsed */
$parsed = parse_url($uri);
$host = $parsed['host'];
$resource = $parsed['path'] ?? '';
Expand Down
13 changes: 6 additions & 7 deletions src/Header/HeaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class HeaderFactory
{
/**
* @param array<string, string>|null $attributes
* @param array<string, mixed>|null $attributes
*/
public static function create(string $fieldName, array $attributes = null): Header
{
Expand Down Expand Up @@ -39,22 +39,21 @@ public static function createFromString(string $fieldName, string $fieldValue, a
}

/**
* @param callable(): void $onError
* @param callable(): never $onError
* @throws FieldValueParserException
* @throws NotHawkAuthorizationException
*/
public static function createFromHeaderObjectOrString(
string $fieldName,
mixed $headerObjectOrString,
callable $onError
): Header|string|null {
): Header {
if (is_string($headerObjectOrString)) {
return static::createFromString($fieldName, $headerObjectOrString);
} elseif ($headerObjectOrString instanceof Header) {
}
if ($headerObjectOrString instanceof Header) {
return $headerObjectOrString;
} else {
call_user_func($onError);
}
return null;
call_user_func($onError);
}
}
4 changes: 4 additions & 0 deletions src/Header/HeaderParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class HeaderParser
/**
* @param string[]|null $requiredKeys
* @return array<string, string>
* @throws FieldValueParserException
*/
public static function parseFieldValue(string $fieldValue, array $requiredKeys = null): array
{
Expand All @@ -18,6 +19,9 @@ public static function parseFieldValue(string $fieldValue, array $requiredKeys =
$fieldValue = substr($fieldValue, 5);
foreach (explode(', ', $fieldValue) as $part) {
$equalsPos = strpos($part, '=');
if ($equalsPos === false) {
throw new FieldValueParserException('field did not contain a "="');
}
$key = substr($part, 0, $equalsPos);
$value = substr($part, $equalsPos + 1);
$attributes[$key] = trim($value, '"');
Expand Down
2 changes: 1 addition & 1 deletion src/Server/UnauthorizedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UnauthorizedException extends Exception
private ?Header $header = null;

/**
* @param array<string, string> $attributes
* @param array<string, mixed> $attributes
*/
public function __construct(?string $message = null, private array $attributes = [])
{
Expand Down