From 982192c2d25d8ccf67104e62640a3bcaa6e2068a Mon Sep 17 00:00:00 2001 From: Marc Reichel Date: Mon, 12 Jan 2026 11:41:04 +0100 Subject: [PATCH] chore: PHPStan Level 6 --- composer.json | 1 + phpstan.neon | 6 ++---- src/Client/ArtemeonHttpClient.php | 2 ++ .../Decorator/OAuth2/ClientCredentials.php | 2 ++ src/Client/HttpClientTestFactory.php | 8 +++++++- src/Client/Options/ClientOptionsConverter.php | 4 ++++ src/Http/Body/Encoder/FormUrlEncoder.php | 4 ++-- src/Http/Body/Encoder/JsonEncoder.php | 3 ++- src/Http/Header/Header.php | 16 +++++++++++++--- src/Http/Header/Headers.php | 4 ++++ src/Http/Message.php | 2 ++ src/Http/Uri.php | 13 ++++++------- src/Stream/Stream.php | 2 ++ 13 files changed, 49 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index ff3944f..8fa5fee 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ } ], "config": { + "process-timeout": 0, "allow-plugins": { "phpstan/extension-installer": true, "pestphp/pest-plugin": true diff --git a/phpstan.neon b/phpstan.neon index 60afcbd..7218d83 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,5 @@ -includes: - - phar://phpstan.phar/conf/bleedingEdge.neon - parameters: - level: 5 + level: 6 paths: - src + treatPhpDocTypesAsCertain: false diff --git a/src/Client/ArtemeonHttpClient.php b/src/Client/ArtemeonHttpClient.php index 2542ca8..031e1af 100644 --- a/src/Client/ArtemeonHttpClient.php +++ b/src/Client/ArtemeonHttpClient.php @@ -85,6 +85,8 @@ final public function send(Request $request, ?ClientOptions $clientOptions = nul * -------- 2. GuzzleClientException -> ClientResponseException * ``` * + * @param array $guzzleOptions + * * @throws HttpClientException */ private function doSend(Request $request, array $guzzleOptions): Response diff --git a/src/Client/Decorator/OAuth2/ClientCredentials.php b/src/Client/Decorator/OAuth2/ClientCredentials.php index b428682..89de3ff 100644 --- a/src/Client/Decorator/OAuth2/ClientCredentials.php +++ b/src/Client/Decorator/OAuth2/ClientCredentials.php @@ -61,6 +61,8 @@ public static function forHeaderAuthorization(string $clientId, string $clientSe /** * Creates the required key => value pairs for the Access Token Request. + * + * @return array */ public function toArray(bool $includeClientCredentials = true): array { diff --git a/src/Client/HttpClientTestFactory.php b/src/Client/HttpClientTestFactory.php index c714b0e..77cc2c7 100644 --- a/src/Client/HttpClientTestFactory.php +++ b/src/Client/HttpClientTestFactory.php @@ -28,13 +28,15 @@ */ class HttpClientTestFactory { + /** + * @var array> + */ private array $transactionLog = []; private readonly MockHandler $mockHandler; private static HttpClientTestFactory $instance; public function __construct() { - $this->transactionLog = []; $this->mockHandler = new MockHandler(); } @@ -111,6 +113,8 @@ public static function withMockHandler(): HttpClient /** * Register the responses to mock. * + * @param list $responses + * * @throws InvalidArgumentException */ public static function mockResponses(array $responses): void @@ -128,6 +132,8 @@ public static function mockResponses(array $responses): void /** * Return the recorded transaction log array. + * + * @return array> */ public static function getTransactionLog(): array { diff --git a/src/Client/Options/ClientOptionsConverter.php b/src/Client/Options/ClientOptionsConverter.php index f77c7c9..319bb4d 100644 --- a/src/Client/Options/ClientOptionsConverter.php +++ b/src/Client/Options/ClientOptionsConverter.php @@ -22,6 +22,8 @@ class ClientOptionsConverter { /** * Converts the given ClientOptions to the guzzle options array format. + * + * @return array */ public function toGuzzleOptionsArray(ClientOptions $clientOptions): array { @@ -60,6 +62,8 @@ private function createVerifyKey(ClientOptions $clientOptions): bool | string /** * @see http://docs.guzzlephp.org/en/6.5/request-options.html#allow-redirects + * + * @return array{max:int,referer:bool}|false */ private function createAllowRedirectsKey(ClientOptions $clientOptions): array | false { diff --git a/src/Http/Body/Encoder/FormUrlEncoder.php b/src/Http/Body/Encoder/FormUrlEncoder.php index c92c6c7..f5fb238 100644 --- a/src/Http/Body/Encoder/FormUrlEncoder.php +++ b/src/Http/Body/Encoder/FormUrlEncoder.php @@ -26,7 +26,7 @@ class FormUrlEncoder implements Encoder /** * FormUrlEncoder constructor. * - * @param array $formValues Array with the form values to encode: ['formFieldName' = 'value'], + * @param array $formValues Array with the form values to encode: ['formFieldName' = 'value'], */ private function __construct(private readonly array $formValues) { @@ -40,7 +40,7 @@ private function __construct(private readonly array $formValues) * $encoder->encode(); * ``` * - * @param array $formValues ['formFieldName' = 'value'], + * @param array $formValues ['formFieldName' = 'value'], */ public static function fromArray(array $formValues): self { diff --git a/src/Http/Body/Encoder/JsonEncoder.php b/src/Http/Body/Encoder/JsonEncoder.php index f5feb63..0692691 100644 --- a/src/Http/Body/Encoder/JsonEncoder.php +++ b/src/Http/Body/Encoder/JsonEncoder.php @@ -25,6 +25,7 @@ class JsonEncoder implements Encoder { /** + * @param array|object $value * @param int $options Optional json encode options: @see https://www.php.net/manual/de/function.json-encode.php * @param string $mimeType Optional custom mime type */ @@ -51,7 +52,7 @@ private function __construct( * $encoder->encode(); * ``` * - * @param array $value Array to encode, associative array always encoded as json object + * @param array $value Array to encode, associative array always encoded as json object * @param int $options Optional Bitmask of json constants: @see https://www.php.net/manual/en/function.json-encode.php * @param string $mimeType Optional custom mime type */ diff --git a/src/Http/Header/Header.php b/src/Http/Header/Header.php index ab59b43..fcb8965 100644 --- a/src/Http/Header/Header.php +++ b/src/Http/Header/Header.php @@ -21,6 +21,10 @@ class Header { private readonly string $name; + + /** + * @var array + */ private array $values; /** @@ -50,7 +54,7 @@ public static function fromString(string $name, string $value): self * Named constructor to create an instance based on the given string[] values. * * @param string $name Name of the http header field - * @param array $values Array of header values + * @param array $values Array of header values * @throws InvalidArgumentException */ public static function fromArray(string $name, array $values): self @@ -89,7 +93,7 @@ public function addValue(string $value): void /** * Add an array of values to the header, doublets will be skipped. * - * @param array $values The string value to add + * @param array $values The string values to add */ public function addValues(array $values): void { @@ -105,6 +109,8 @@ public function addValues(array $values): void /** * Returns all value of the http header field. + * + * @return array */ public function getValues(): array { @@ -122,7 +128,11 @@ public function getValue(): string /** * Check and normalize header values. * + * @param non-empty-array $values + * * @throws InvalidArgumentException + * + * @return non-empty-array */ private function assertValues(array $values): array { @@ -139,7 +149,7 @@ private function assertValues(array $values): array } } - return $values; + return array_values($values); } /** diff --git a/src/Http/Header/Headers.php b/src/Http/Header/Headers.php index 5f0f971..7475134 100644 --- a/src/Http/Header/Headers.php +++ b/src/Http/Header/Headers.php @@ -21,6 +21,8 @@ /** * Header collection class for http requests and responses. + * + * @implements IteratorAggregate */ class Headers implements Countable, IteratorAggregate { @@ -152,6 +154,8 @@ public function get(string $headerField): Header /** * @inheritDoc + * + * @return ArrayIterator */ #[Override] public function getIterator(): ArrayIterator diff --git a/src/Http/Message.php b/src/Http/Message.php index e3eeb19..2823ab0 100644 --- a/src/Http/Message.php +++ b/src/Http/Message.php @@ -201,6 +201,8 @@ public function withBody(StreamInterface $body): MessageInterface /** * Checks the header data. * + * @param array|float|int|string $value + * * @throws InvalidArgumentException */ private function assertHeader(string $name, array | float | int | string $value): void diff --git a/src/Http/Uri.php b/src/Http/Uri.php index 2822d15..3695a2a 100644 --- a/src/Http/Uri.php +++ b/src/Http/Uri.php @@ -71,7 +71,7 @@ private function __construct(string $uri) * Named constructor to create an instance based on the given url and query params. * * @param string $uri Url string with protocol - * @param array $queryParams Query params array: ["varName" => value] + * @param array $queryParams Query params array: ["varName" => value] * @throws InvalidArgumentException */ public static function fromQueryParams(string $uri, array $queryParams): self @@ -260,6 +260,9 @@ private function filterUserInfoComponent(string $component): string ); } + /** + * @param string[] $match + */ private function rawurlencodeMatchZero(array $match): string { return rawurlencode((string) $match[0]); @@ -293,7 +296,7 @@ public function withPort(?int $port): self * @inheritDoc */ #[Override] - public function withPath(array | bool | int | string $path): self + public function withPath(string $path): self { $cloned = clone $this; $cloned->path = $cloned->filterPath($path); @@ -367,12 +370,8 @@ private function filterHost(string $host): string * * @throws InvalidArgumentException */ - private function filterPath(array | bool | int | string $path): string + private function filterPath(string $path): string { - if (!is_string($path)) { - throw new InvalidArgumentException('path must be a string'); - } - $pattern = '/(?:[^' . self::UNRESERVED . self::DELIMITER . "%:@\/]++|%(?![A-Fa-f0-9]{2}))/"; return preg_replace_callback($pattern, [$this, 'encode'], $path); diff --git a/src/Stream/Stream.php b/src/Stream/Stream.php index 5f31479..475763e 100644 --- a/src/Stream/Stream.php +++ b/src/Stream/Stream.php @@ -30,6 +30,8 @@ class Stream implements AppendableStream /** * @see https://www.php.net/manual/de/function.stream-get-meta-data + * + * @var array */ private array $metaData;