From 515e5a390842af15d8782b3523b733bd1b9dc776 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Fri, 23 Feb 2024 12:06:02 +0100 Subject: [PATCH] Format and simplify --- .github/workflows/autoformat.yml | 4 +-- composer.json | 2 +- phpunit.xml | 7 ++-- src/BadMultipartRequestGraphQLException.php | 6 ++-- src/RequestParser.php | 18 ++++------ tests/Unit/RequestParserTest.php | 40 ++++++--------------- 6 files changed, 25 insertions(+), 52 deletions(-) diff --git a/.github/workflows/autoformat.yml b/.github/workflows/autoformat.yml index e81b47e..ad35661 100644 --- a/.github/workflows/autoformat.yml +++ b/.github/workflows/autoformat.yml @@ -18,7 +18,7 @@ jobs: extensions: mbstring php-version: 8.3 - - run: composer install --no-interaction --no-progress --no-suggest + - run: composer install --no-interaction --no-progress - run: composer normalize @@ -54,7 +54,7 @@ jobs: extensions: mbstring php-version: 7.2 - - run: composer install --no-interaction --no-progress --no-suggest + - run: composer install --no-interaction --no-progress - run: vendor/bin/php-cs-fixer fix diff --git a/composer.json b/composer.json index b549958..37174b2 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "require-dev": { "ergebnis/composer-normalize": "^2.11", "jangregor/phpstan-prophecy": "^1", - "mll-lab/php-cs-fixer-config": "^4.4", + "mll-lab/php-cs-fixer-config": "^4", "orchestra/testbench": "~3.6.0 || ~3.7.0 || ~3.8.0 || ~3.9.0 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9 || ^9.x-dev", "phpstan/extension-installer": "^1", "phpstan/phpstan": "^1", diff --git a/phpunit.xml b/phpunit.xml index a7f5136..da05c57 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,8 +1,7 @@ @@ -11,7 +10,7 @@ - src + src diff --git a/src/BadMultipartRequestGraphQLException.php b/src/BadMultipartRequestGraphQLException.php index 7dec415..e6ac363 100644 --- a/src/BadMultipartRequestGraphQLException.php +++ b/src/BadMultipartRequestGraphQLException.php @@ -6,10 +6,8 @@ class BadMultipartRequestGraphQLException extends BadRequestHttpException { - /** - * @param array $headers - */ - public function __construct(string $message, \Throwable $previous = null, int $code = 0, array $headers = []) + /** @param array $headers */ + public function __construct(string $message, ?\Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct( "{$message} Be sure to conform to the GraphQL multipart request specification (https://github.com/jaydenseric/graphql-multipart-request-spec).", diff --git a/src/RequestParser.php b/src/RequestParser.php index 5bca090..98469b9 100644 --- a/src/RequestParser.php +++ b/src/RequestParser.php @@ -9,14 +9,10 @@ use Safe\Exceptions\JsonException; use function Safe\json_decode; -/** - * Follows https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md. - */ +/** Follows https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md. */ class RequestParser { - /** - * @var \GraphQL\Server\Helper - */ + /** @var Helper */ protected $helper; public function __construct() @@ -28,8 +24,8 @@ public function __construct() * Converts an incoming HTTP request to one or more OperationParams. * * @throws \GraphQL\Server\RequestError - * @throws \Laragraph\Utils\BadRequestGraphQLException - * @throws \Laragraph\Utils\BadMultipartRequestGraphQLException + * @throws BadRequestGraphQLException + * @throws BadMultipartRequestGraphQLException * * @return \GraphQL\Server\OperationParams|array */ @@ -48,8 +44,8 @@ public function parseRequest(Request $request) /** * Extracts the body parameters from the request. * - * @throws \Laragraph\Utils\BadMultipartRequestGraphQLException - * @throws \Laragraph\Utils\BadRequestGraphQLException + * @throws BadMultipartRequestGraphQLException + * @throws BadRequestGraphQLException * * @return array */ @@ -96,7 +92,7 @@ protected function bodyParams(Request $request): array * * Follows https://github.com/jaydenseric/graphql-multipart-request-spec. * - * @throws \Laragraph\Utils\BadMultipartRequestGraphQLException + * @throws BadMultipartRequestGraphQLException * * @return array */ diff --git a/tests/Unit/RequestParserTest.php b/tests/Unit/RequestParserTest.php index a4834ca..e8460fb 100644 --- a/tests/Unit/RequestParserTest.php +++ b/tests/Unit/RequestParserTest.php @@ -24,9 +24,7 @@ public function testGetWithQuery(): void self::assertSame($query, $params->query); } - /** - * @dataProvider jsonLikeContentTypes - */ + /** @dataProvider jsonLikeContentTypes */ public function testPostWithJsonLike(string $contentType): void { $query = /** @lang GraphQL */ '{ foo }'; @@ -43,9 +41,7 @@ public function testPostWithJsonLike(string $contentType): void self::assertSame($query, $params->query); } - /** - * @return iterable - */ + /** @return iterable */ public static function jsonLikeContentTypes(): iterable { yield ['application/json']; @@ -53,9 +49,7 @@ public static function jsonLikeContentTypes(): iterable yield ['application/json;charset=UTF-8']; } - /** - * @dataProvider graphQLContentTypes - */ + /** @dataProvider graphQLContentTypes */ public function testPostWithQueryApplicationGraphQL(string $contentType): void { $query = /** @lang GraphQL */ '{ foo }'; @@ -72,18 +66,14 @@ public function testPostWithQueryApplicationGraphQL(string $contentType): void self::assertSame($query, $params->query); } - /** - * @return iterable - */ + /** @return iterable */ public static function graphQLContentTypes(): iterable { yield ['application/graphql']; yield ['application/graphql;charset=UTF-8']; } - /** - * @dataProvider formContentTypes - */ + /** @dataProvider formContentTypes */ public function testPostWithRegularForm(string $contentType): void { $query = /** @lang GraphQL */ '{ foo }'; @@ -100,9 +90,7 @@ public function testPostWithRegularForm(string $contentType): void self::assertSame($query, $params->query); } - /** - * @return iterable - */ + /** @return iterable */ public static function formContentTypes(): iterable { yield ['application/x-www-form-urlencoded']; @@ -145,9 +133,7 @@ public function testPostDefaultsToRegularForm(): void self::assertSame($query, $params->query); } - /** - * @dataProvider nonsensicalContentTypes - */ + /** @dataProvider nonsensicalContentTypes */ public function testNonsensicalContentTypes(string $contentType): void { $request = $this->makeRequest( @@ -163,9 +149,7 @@ public function testNonsensicalContentTypes(string $contentType): void $parser->parseRequest($request); } - /** - * @return iterable - */ + /** @return iterable */ public static function nonsensicalContentTypes(): iterable { yield ['foobar']; @@ -217,9 +201,7 @@ public function testNonArrayJson(): void $parser->parseRequest($request); } - /** - * @dataProvider multipartFormContentTypes - */ + /** @dataProvider multipartFormContentTypes */ public function testMultipartFormRequest(string $contentType): void { $file = UploadedFile::fake()->create('image.jpg', 500); @@ -260,9 +242,7 @@ public function testMultipartFormRequest(string $contentType): void self::assertSame($file, $variables['file']); } - /** - * @return iterable - */ + /** @return iterable */ public static function multipartFormContentTypes(): iterable { yield ['multipart/form-data'];