Skip to content

Commit 770d340

Browse files
authored
Merge pull request #66 from thecodingmachine/6.0
Add SF 6 support
2 parents 1a7d828 + 671f5d1 commit 770d340

9 files changed

+38
-65
lines changed

.travis.yml

+3-14
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,13 @@ env:
1313
matrix:
1414
fast_finish: true
1515
include:
16-
# Test the latest stable release
17-
- php: 7.2
18-
- php: 8.0
19-
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
20-
2116
# Test LTS versions.
22-
- php: 8.0
23-
env: DEPENDENCIES="symfony/lts:^4"
24-
25-
# Latest commit to master
26-
- php: 8.0
27-
env: STABILITY="dev"
17+
- php: 8.1
18+
env: DEPENDENCIES="symfony/^6"
2819

2920
allow_failures:
3021
# Minimum supported dependencies with the latest and oldest PHP version
31-
- php: 8.0
32-
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
33-
- php: 7.2
22+
- php: 8.1
3423
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
3524
# Dev-master is allowed to fail.
3625
- env: STABILITY="dev"

composer.json

+14-9
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
],
1919
"require" : {
2020
"php" : ">=7.2",
21-
"thecodingmachine/graphqlite" : "^5.0",
22-
"symfony/validator": "^4.2 | ^5 | ^6" ,
23-
"doctrine/annotations": "^1.6"
21+
"thecodingmachine/graphqlite" : "^6.0",
22+
"symfony/validator": "^6" ,
23+
"doctrine/annotations": "^1.13"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^8.4.1",
26+
"phpunit/phpunit": "^9.6.5",
2727
"mouf/picotainer": "^1.1",
28-
"phpstan/phpstan": "^0.12.14",
28+
"phpstan/phpstan": "^1.8",
2929
"php-coveralls/php-coveralls": "^2.1.0",
30-
"symfony/translation": "^4 | ^5 | ^6",
31-
"doctrine/coding-standard": "^9.0"
30+
"symfony/translation": "^6",
31+
"doctrine/coding-standard": "^11.1"
3232
},
3333
"scripts": {
3434
"phpstan": "phpstan analyse src/ -c phpstan.neon --level=7 --no-progress",
@@ -48,9 +48,14 @@
4848
},
4949
"extra": {
5050
"branch-alias": {
51-
"dev-master": "5.0.x-dev"
51+
"dev-master": "6.0.x-dev"
5252
}
5353
},
5454
"minimum-stability": "dev",
55-
"prefer-stable": true
55+
"prefer-stable": true,
56+
"config": {
57+
"allow-plugins": {
58+
"dealerdirect/phpcodesniffer-composer-installer": true
59+
}
60+
}
5661
}

phpstan.neon

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
parameters:
22
ignoreErrors:
33

4+
excludePaths:
5+
- vendor
6+
- cache
7+
- .phpstan-cache
8+
49
#includes:
510
# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

src/Annotations/Assertion.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ class Assertion implements ParameterAnnotationInterface
2828
/** @var Constraint[] */
2929
private $constraint;
3030

31-
/**
32-
* @param array<string, mixed> $values
33-
*/
31+
/** @param array<string, mixed> $values */
3432
public function __construct(array $values)
3533
{
3634
if (! isset($values['for'])) {
@@ -50,9 +48,7 @@ public function getTarget(): string
5048
return $this->for;
5149
}
5250

53-
/**
54-
* @return Constraint[]
55-
*/
51+
/** @return Constraint[] */
5652
public function getConstraint(): array
5753
{
5854
return $this->constraint;

src/ConstraintViolationException.php

+2-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ConstraintViolationException extends Exception implements GraphQLException
1616
public function __construct(ConstraintViolationInterface $violation)
1717
{
1818
parent::__construct((string) $violation->getMessage(), 400);
19+
1920
$this->violation = $violation;
2021
}
2122

@@ -27,24 +28,14 @@ public function isClientSafe(): bool
2728
return true;
2829
}
2930

30-
/**
31-
* Returns string describing a category of the error.
32-
*
33-
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
34-
*/
35-
public function getCategory(): string
36-
{
37-
return 'Validate';
38-
}
39-
4031
/**
4132
* Returns the "extensions" object attached to the GraphQL error.
4233
*
4334
* @return array<string, mixed>
4435
*/
4536
public function getExtensions(): array
4637
{
47-
$extensions = [];
38+
$extensions = ['category' => 'Validate'];
4839
$code = $this->violation->getCode();
4940
if (! empty($code)) {
5041
$extensions['code'] = $code;

src/Mappers/Parameters/AssertParameterMiddleware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(ConstraintValidatorFactoryInterface $constraintValid
3939
$this->translator = $translator;
4040
}
4141

42-
public function mapParameter(ReflectionParameter $refParameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface
42+
public function mapParameter(ReflectionParameter $refParameter, DocBlock $docBlock, Type|null $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface
4343
{
4444
/** @var Assertion[] $assertionAnnotations */
4545
$assertionAnnotations = $parameterAnnotations->getAnnotationsByType(Assertion::class);

src/Mappers/Parameters/ParameterValidator.php

+6-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GraphQL\Type\Definition\InputType;
88
use GraphQL\Type\Definition\ResolveInfo;
9+
use GraphQL\Type\Definition\Type;
910
use Symfony\Component\Validator\Constraint;
1011
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
1112
use Symfony\Component\Validator\Context\ExecutionContext;
@@ -29,9 +30,7 @@ class ParameterValidator implements InputTypeParameterInterface
2930
/** @var TranslatorInterface */
3031
private $translator;
3132

32-
/**
33-
* @param Constraint[] $constraints
34-
*/
33+
/** @param Constraint[] $constraints */
3534
public function __construct(InputTypeParameterInterface $parameter, string $parameterName, array $constraints, ConstraintValidatorFactoryInterface $constraintValidatorFactory, ValidatorInterface $validator, TranslatorInterface $translator)
3635
{
3736
$this->parameter = $parameter;
@@ -42,13 +41,8 @@ public function __construct(InputTypeParameterInterface $parameter, string $para
4241
$this->translator = $translator;
4342
}
4443

45-
/**
46-
* @param array<string, mixed> $args
47-
* @param mixed $context
48-
*
49-
* @return mixed
50-
*/
51-
public function resolve(?object $source, array $args, $context, ResolveInfo $info)
44+
/** @param array<string, mixed> $args */
45+
public function resolve(object|null $source, array $args, mixed $context, ResolveInfo $info): mixed
5246
{
5347
$value = $this->parameter->resolve($source, $args, $context, $info);
5448

@@ -69,7 +63,7 @@ public function resolve(?object $source, array $args, $context, ResolveInfo $inf
6963
return $value;
7064
}
7165

72-
public function getType(): InputType
66+
public function getType(): InputType&Type
7367
{
7468
return $this->parameter->getType();
7569
}
@@ -79,10 +73,7 @@ public function hasDefaultValue(): bool
7973
return $this->parameter->hasDefaultValue();
8074
}
8175

82-
/**
83-
* @return mixed
84-
*/
85-
public function getDefaultValue()
76+
public function getDefaultValue(): mixed
8677
{
8778
return $this->parameter->getDefaultValue();
8879
}

src/ValidationFailedException.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ class ValidationFailedException extends InvalidArgumentException implements Grap
1616
/** @var ConstraintViolationException[] */
1717
private $exceptions = [];
1818

19-
/**
20-
* @param ConstraintViolationListInterface<ConstraintViolationInterface> $constraintViolationList
21-
*/
19+
/** @param ConstraintViolationListInterface<ConstraintViolationInterface> $constraintViolationList */
2220
public function __construct(ConstraintViolationListInterface $constraintViolationList)
2321
{
2422
parent::__construct('Validation failed:', 400);
23+
2524
foreach ($constraintViolationList as $constraintViolation) {
2625
$this->add($constraintViolation);
2726
}
@@ -33,9 +32,7 @@ private function add(ConstraintViolationInterface $violation): void
3332
$this->message .= "\n" . $violation->getMessage();
3433
}
3534

36-
/**
37-
* @return (ClientAware&Throwable)[]
38-
*/
35+
/** @return (ClientAware&Throwable)[] */
3936
public function getExceptions(): array
4037
{
4138
return $this->exceptions;

tests/ConstraintValidationExceptionTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ public function testException()
1313
$exception = new ConstraintViolationException(new ConstraintViolation('foo', 'foo {bar}', ['bar' => 'baz'], null, null, 'invalidValue', null, 'myCode'));
1414
$this->assertSame(400, $exception->getCode());
1515
$this->assertTrue($exception->isClientSafe());
16-
$this->assertSame('Validate', $exception->getCategory());
17-
$this->assertSame(['code' => 'myCode'], $exception->getExtensions());
16+
$this->assertSame(['category' => 'Validate', 'code' => 'myCode'], $exception->getExtensions());
1817

1918
$exception = new ConstraintViolationException(new ConstraintViolation('foo', 'foo {bar}', ['bar' => 'baz'], null, null, 'invalidValue'));
20-
$this->assertSame([], $exception->getExtensions());
19+
$this->assertSame(['category' => 'Validate'], $exception->getExtensions());
2120
}
2221
}

0 commit comments

Comments
 (0)