Skip to content

Commit

Permalink
Format and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Feb 23, 2024
1 parent f8743fa commit 515e5a3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/autoformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.result.cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
>
<testsuites>
<testsuite name="Unit">
Expand All @@ -11,7 +10,7 @@
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</source>
</phpunit>
6 changes: 2 additions & 4 deletions src/BadMultipartRequestGraphQLException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

class BadMultipartRequestGraphQLException extends BadRequestHttpException
{
/**
* @param array<mixed> $headers
*/
public function __construct(string $message, \Throwable $previous = null, int $code = 0, array $headers = [])
/** @param array<mixed> $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).",
Expand Down
18 changes: 7 additions & 11 deletions src/RequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<int, \GraphQL\Server\OperationParams>
*/
Expand All @@ -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<mixed>
*/
Expand Down Expand Up @@ -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<mixed>
*/
Expand Down
40 changes: 10 additions & 30 deletions tests/Unit/RequestParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 }';
Expand All @@ -43,19 +41,15 @@ public function testPostWithJsonLike(string $contentType): void
self::assertSame($query, $params->query);
}

/**
* @return iterable<array{string}>
*/
/** @return iterable<array{string}> */
public static function jsonLikeContentTypes(): iterable
{
yield ['application/json'];
yield ['application/graphql+json'];
yield ['application/json;charset=UTF-8'];
}

/**
* @dataProvider graphQLContentTypes
*/
/** @dataProvider graphQLContentTypes */
public function testPostWithQueryApplicationGraphQL(string $contentType): void
{
$query = /** @lang GraphQL */ '{ foo }';
Expand All @@ -72,18 +66,14 @@ public function testPostWithQueryApplicationGraphQL(string $contentType): void
self::assertSame($query, $params->query);
}

/**
* @return iterable<array{string}>
*/
/** @return iterable<array{string}> */
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 }';
Expand All @@ -100,9 +90,7 @@ public function testPostWithRegularForm(string $contentType): void
self::assertSame($query, $params->query);
}

/**
* @return iterable<array{string}>
*/
/** @return iterable<array{string}> */
public static function formContentTypes(): iterable
{
yield ['application/x-www-form-urlencoded'];
Expand Down Expand Up @@ -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(
Expand All @@ -163,9 +149,7 @@ public function testNonsensicalContentTypes(string $contentType): void
$parser->parseRequest($request);
}

/**
* @return iterable<array{string}>
*/
/** @return iterable<array{string}> */
public static function nonsensicalContentTypes(): iterable
{
yield ['foobar'];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -260,9 +242,7 @@ public function testMultipartFormRequest(string $contentType): void
self::assertSame($file, $variables['file']);
}

/**
* @return iterable<array{string}>
*/
/** @return iterable<array{string}> */
public static function multipartFormContentTypes(): iterable
{
yield ['multipart/form-data'];
Expand Down

0 comments on commit 515e5a3

Please sign in to comment.