diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a372eb1..7df3892 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,8 +5,7 @@ version: 2 updates: - - package-ecosystem: "" # See documentation for possible values + - package-ecosystem: "composer" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "weekly" - diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3a8f7bd..b5f24a8 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,9 +21,10 @@ jobs: - "highest" - "locked" php-version: - - "8.1" - "8.2" - "8.3" + - "8.4" + - "8.5" operating-system: - "ubuntu-latest" - "windows-latest" @@ -57,9 +58,10 @@ jobs: dependencies: - "locked" php-version: - - "8.1" - "8.2" - "8.3" + - "8.4" + - "8.5" operating-system: - "ubuntu-latest" @@ -92,7 +94,7 @@ jobs: dependencies: - "locked" php-version: - - "8.3" + - "8.4" operating-system: - "ubuntu-latest" diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index ba2c78d..60ba0fd 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -18,7 +18,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "pcov" - php-version: "8.3" + php-version: "8.4" ini-values: memory_limit=-1 - name: "Install dependencies" diff --git a/composer.json b/composer.json index 240f5c4..6b1ceae 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,10 @@ } ], "require": { - "php": "^8.1.0", + "php": "^8.2.0", "league/openapi-psr7-validator": "0.*", "devizzent/cebe-php-openapi": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^2.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", "psr/log": "^1.0|^2.0|^3.0", @@ -31,7 +31,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.11", - "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^11.0 || ^12.0" } } diff --git a/src/Bridge/LeagueOpenAPIValidation/Exception/InvalidOpenApiDefinitionException.php b/src/Bridge/LeagueOpenAPIValidation/Exception/InvalidOpenApiDefinitionException.php index 1a92b84..55a53f1 100644 --- a/src/Bridge/LeagueOpenAPIValidation/Exception/InvalidOpenApiDefinitionException.php +++ b/src/Bridge/LeagueOpenAPIValidation/Exception/InvalidOpenApiDefinitionException.php @@ -9,7 +9,7 @@ class InvalidOpenApiDefinitionException extends InvalidArgumentException { public function __construct(Throwable $previous) { - parent::__construct(sprintf( + parent::__construct(\sprintf( "The given OpenApi definition can't be loaded:\n%s -> %s", $previous::class, $previous->getMessage() diff --git a/src/Bridge/LeagueOpenAPIValidation/Factory.php b/src/Bridge/LeagueOpenAPIValidation/Factory.php index 3217888..c012141 100644 --- a/src/Bridge/LeagueOpenAPIValidation/Factory.php +++ b/src/Bridge/LeagueOpenAPIValidation/Factory.php @@ -23,7 +23,7 @@ public static function fromYamlFile(string $path): self { if (!is_readable($path)) { throw new InvalidArgumentException( - sprintf('Filename given isn\'t readable: %s', $path) + \sprintf('Filename given isn\'t readable: %s', $path) ); } @@ -36,7 +36,7 @@ public static function fromJsonFile(string $path): self { if (!is_readable($path)) { throw new InvalidArgumentException( - sprintf('Filename given isn\'t readable: %s', $path) + \sprintf('Filename given isn\'t readable: %s', $path) ); } diff --git a/src/Http/Factory/Headers.php b/src/Http/Factory/Headers.php index a3a32e6..85e6aab 100644 --- a/src/Http/Factory/Headers.php +++ b/src/Http/Factory/Headers.php @@ -25,7 +25,18 @@ public function __construct(mixed $headers = []) } foreach ($headers as $name => $values) { - $this->set($name, $values); + if (\is_string($values)) { + $this->set($name, $values); + } elseif (\is_array($values)) { + foreach ($values as $value) { + if (!\is_string($value)) { + throw new InvalidArgumentException('Header values must be string[]|string.'); + } + $this->set($name, $value); + } + } else { + throw new InvalidArgumentException('Header values must be string[]|string.'); + } } } @@ -40,7 +51,7 @@ public function __toString(): string foreach ($this->headers as $name => $values) { $name = ucwords($name, '-'); foreach ($values as $value) { - $asString .= sprintf('%s: %s', $name, $value).PHP_EOL; + $asString .= \sprintf('%s: %s', $name, $value).PHP_EOL; } } diff --git a/src/Http/Factory/Resolver/FakerValueResolver.php b/src/Http/Factory/Resolver/FakerValueResolver.php index 9fba5a3..7bf0fd7 100644 --- a/src/Http/Factory/Resolver/FakerValueResolver.php +++ b/src/Http/Factory/Resolver/FakerValueResolver.php @@ -38,7 +38,7 @@ private function resolveFakerValue(array $matches): mixed ); } catch (InvalidArgumentException) { } catch (JsonException $error) { - $message = sprintf( + $message = \sprintf( "Can't extract the arguments to call method %s: [%s]", $matches[1], $matches[2] diff --git a/src/Http/Factory/Uri.php b/src/Http/Factory/Uri.php index 52e6507..19539fd 100644 --- a/src/Http/Factory/Uri.php +++ b/src/Http/Factory/Uri.php @@ -12,18 +12,42 @@ class Uri implements Stringable public function __construct(mixed $value) { if (\is_array($value)) { - if (!isset($value['base'])) { + if (!\is_string($value['base'])) { throw new InvalidArgumentException( 'If you want to build an URI from an array, use the schema: [ base => string, ?parameters => [string => mixed]' ); } + // Check if parameters is a valid string[] $parameters = $value['parameters'] ?? []; - $value = str_replace(array_keys($parameters), $parameters, (string) $value['base']); - } elseif (!\is_string($value)) { + if (!\is_array($parameters)) { + throw new InvalidArgumentException('value parameters must be an array.'); + } + + $search = []; + $replace = []; + foreach ($parameters as $name => $parameter) { + if (!\is_string($name) || !\is_string($parameter)) { + throw new InvalidArgumentException(\sprintf( + 'Invalid parameter given {name: %s, parameter: %s}', + var_export($name, true), + var_export($parameter, true) + )); + } + $search[] = $name; + $replace[] = $parameter; + } + + $this->uri = str_replace( + $search, + $replace, + (string) $value['base'] + ); + } elseif (\is_string($value)) { + $this->uri = $value; + } else { throw new InvalidArgumentException('$value must be a string or an array.'); } - $this->uri = $value; } public function __toString(): string diff --git a/src/Validator/Exception/ApiSchemaException.php b/src/Validator/Exception/ApiSchemaException.php index ac0a4b4..188f195 100644 --- a/src/Validator/Exception/ApiSchemaException.php +++ b/src/Validator/Exception/ApiSchemaException.php @@ -10,7 +10,7 @@ class ApiSchemaException extends RuntimeException implements ValidationException public function __construct( Throwable $previous ) { - $message = sprintf( + $message = \sprintf( 'Something went wrong with the API schema: %s.', $previous->getMessage() ); diff --git a/src/Validator/Exception/DataSchemaException.php b/src/Validator/Exception/DataSchemaException.php index 3884c28..6b1520f 100644 --- a/src/Validator/Exception/DataSchemaException.php +++ b/src/Validator/Exception/DataSchemaException.php @@ -12,7 +12,7 @@ public function __construct( public readonly string $path, Throwable $previous ) { - $message = sprintf( + $message = \sprintf( "Data validation failed for property \"%s\", invalid value: %s\n\n> %s", $path, var_export($value, true), diff --git a/src/Validator/Exception/GenericException.php b/src/Validator/Exception/GenericException.php index 7e4a984..2ca99ac 100644 --- a/src/Validator/Exception/GenericException.php +++ b/src/Validator/Exception/GenericException.php @@ -10,7 +10,7 @@ class GenericException extends RuntimeException implements ValidationException public function __construct( Throwable $previous ) { - $message = sprintf( + $message = \sprintf( 'Something went wrong: %s.', $previous->getMessage() ); diff --git a/src/Validator/Exception/OperationNotFoundException.php b/src/Validator/Exception/OperationNotFoundException.php index 6bb9db3..80f820c 100644 --- a/src/Validator/Exception/OperationNotFoundException.php +++ b/src/Validator/Exception/OperationNotFoundException.php @@ -12,7 +12,7 @@ public function __construct( public readonly RequestInterface $request, Throwable $previous = null ) { - $message = sprintf( + $message = \sprintf( 'API operation for request [%s] %s hasn\'t been found.', $request->getMethod(), $request->getUri() diff --git a/src/Validator/Exception/ResponseNotExpectedException.php b/src/Validator/Exception/ResponseNotExpectedException.php index 453834d..fd0fda4 100644 --- a/src/Validator/Exception/ResponseNotExpectedException.php +++ b/src/Validator/Exception/ResponseNotExpectedException.php @@ -14,7 +14,7 @@ public function __construct( public readonly ResponseInterface $response, Throwable $previous ) { - $message = sprintf( + $message = \sprintf( 'API response with status code %d isn\'t defined in the spec for request [%s] %s.', $response->getStatusCode(), $request->getMethod(), diff --git a/src/Validator/Expectation/ExpectationCollection.php b/src/Validator/Expectation/ExpectationCollection.php index 82ef98c..e8d7132 100644 --- a/src/Validator/Expectation/ExpectationCollection.php +++ b/src/Validator/Expectation/ExpectationCollection.php @@ -22,7 +22,7 @@ public function __construct( } /** - * @return ArrayIterator + * @return ArrayIterator */ public function getIterator(): ArrayIterator { diff --git a/src/Validator/Expectation/StatusCode.php b/src/Validator/Expectation/StatusCode.php index b489268..f1913bc 100644 --- a/src/Validator/Expectation/StatusCode.php +++ b/src/Validator/Expectation/StatusCode.php @@ -16,7 +16,7 @@ public function verify(ResponseInterface $message): ?ExpectationFailedException return $message->getStatusCode() === $this->statusCode ? null : new ExpectationFailedException( - sprintf('Unexpected status code %s, expected %s', $message->getStatusCode(), $this->statusCode), + \sprintf('Unexpected status code %s, expected %s', $message->getStatusCode(), $this->statusCode), $this ); } diff --git a/src/Validator/LoggedRequestValidator.php b/src/Validator/LoggedRequestValidator.php index e73a9fd..1abd66e 100644 --- a/src/Validator/LoggedRequestValidator.php +++ b/src/Validator/LoggedRequestValidator.php @@ -15,13 +15,13 @@ public function __construct( public function validate(RequestInterface $request): void { - $this->logger->debug(sprintf( + $this->logger->debug(\sprintf( "Start testing Request: [%s] %s", $request->getMethod(), $request->getUri() )); $this->decorated->validate($request); - $this->logger->debug(sprintf( + $this->logger->debug(\sprintf( 'Finish testing Request: [%s] %s', $request->getMethod(), $request->getUri() diff --git a/src/Validator/LoggedResponseValidator.php b/src/Validator/LoggedResponseValidator.php index cea5f0e..5b138c9 100644 --- a/src/Validator/LoggedResponseValidator.php +++ b/src/Validator/LoggedResponseValidator.php @@ -16,7 +16,7 @@ public function __construct( public function validate(ResponseInterface $response, RequestInterface $request): void { - $this->logger->debug(sprintf( + $this->logger->debug(\sprintf( 'Start testing Response: [%d] %s', $response->getStatusCode(), $response->getReasonPhrase() @@ -24,7 +24,7 @@ public function validate(ResponseInterface $response, RequestInterface $request) $this->decorated->validate($response, $request); - $this->logger->debug(sprintf( + $this->logger->debug(\sprintf( 'Finish testing Response: [%d] %s', $response->getStatusCode(), $response->getReasonPhrase()