Skip to content

Commit 874835a

Browse files
committed
Stan fixes
1 parent f9e0cab commit 874835a

File tree

11 files changed

+45
-217
lines changed

11 files changed

+45
-217
lines changed

Controller/GraphQL/LoginController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function login(string $userName, string $password, Request $request): Use
8282

8383
// Fire the login event manually
8484
$event = new InteractiveLoginEvent($request, $token);
85+
// @phpstan-ignore-next-line BC for Symfony4
8586
$this->eventDispatcher->dispatch($event, 'security.interactive_login');
8687

8788
return $user;

Controller/GraphqliteController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,16 @@ private function handlePsr7Request(ServerRequestInterface $request, Request $sym
106106
return new JsonResponse($result->toArray($this->debug), $httpCodeDecider->decideHttpStatusCode($result));
107107
}
108108
if (is_array($result)) {
109-
$finalResult = array_map(function (ExecutionResult $executionResult) {
109+
$finalResult = array_map(function (ExecutionResult $executionResult): array {
110110
return $executionResult->toArray($this->debug);
111111
}, $result);
112112
// Let's return the highest result.
113113
$statuses = array_map([$httpCodeDecider, 'decideHttpStatusCode'], $result);
114114
$status = empty($statuses) ? 500 : max($statuses);
115+
115116
return new JsonResponse($finalResult, $status);
116117
}
117-
if ($result instanceof Promise) {
118-
throw new RuntimeException('Only SyncPromiseAdapter is supported');
119-
}
120-
/* @phpstan-ignore-next-line */
121-
throw new RuntimeException('Unexpected response from StandardServer::executePsrRequest'); // @codeCoverageIgnore
118+
119+
throw new RuntimeException('Only SyncPromiseAdapter is supported');
122120
}
123121
}

DependencyInjection/GraphqliteCompilerPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private function mapAdderToTag(string $tag, string $methodName, ContainerBuilder
333333
*/
334334
private function makePublicInjectedServices(ReflectionClass $refClass, AnnotationReader $reader, ContainerBuilder $container, bool $isController): void
335335
{
336-
$services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController) {
336+
$services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController): array {
337337
$services = [];
338338
foreach ($refClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
339339
$field = $reader->getRequestAnnotation($method, Field::class) ?? $reader->getRequestAnnotation($method, Query::class) ?? $reader->getRequestAnnotation($method, Mutation::class);
@@ -347,6 +347,7 @@ private function makePublicInjectedServices(ReflectionClass $refClass, Annotatio
347347
}
348348
}
349349
}
350+
350351
return $services;
351352
});
352353

@@ -485,7 +486,7 @@ private function getClassList(string $namespace, int $globTtl = 2, bool $recursi
485486
// The autoloader might trigger errors if the file does not respect PSR-4 or if the
486487
// Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216)
487488
require_once $phpFile;
488-
// Does it exists now?
489+
// @phpstan-ignore-next-line Does it exists now?
489490
if (! class_exists($className, false)) {
490491
continue;
491492
}

DependencyInjection/GraphqliteExtension.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ public function load(array $configs, ContainerBuilder $container): void
4242
if (!is_array($controllers)) {
4343
$controllers = [ $controllers ];
4444
}
45-
$namespaceController = array_map(function($namespace) { return rtrim($namespace, '\\') . '\\'; }, $controllers);
45+
$namespaceController = array_map(
46+
function($namespace): string {
47+
return rtrim($namespace, '\\') . '\\';
48+
},
49+
$controllers
50+
);
4651
} else {
4752
$namespaceController = [];
4853
}
@@ -51,7 +56,12 @@ public function load(array $configs, ContainerBuilder $container): void
5156
if (!is_array($types)) {
5257
$types = [ $types ];
5358
}
54-
$namespaceType = array_map(function($namespace) { return rtrim($namespace, '\\') . '\\'; }, $types);
59+
$namespaceType = array_map(
60+
function($namespace): string {
61+
return rtrim($namespace, '\\') . '\\';
62+
},
63+
$types
64+
);
5565
} else {
5666
$namespaceType = [];
5767
}
@@ -84,20 +94,6 @@ public function load(array $configs, ContainerBuilder $container): void
8494
->addTag('graphql.root_type_mapper_factory');
8595
}
8696

87-
private function getNamespaceDir(string $namespace): string
88-
{
89-
$classNameMapper = ClassNameMapper::createFromComposerFile(null, null, true);
90-
91-
$possibleFileNames = $classNameMapper->getPossibleFileNames($namespace.'Xxx');
92-
if (count($possibleFileNames) > 1) {
93-
throw new \RuntimeException(sprintf('According to your composer.json, classes belonging to the "%s" namespace can be located in several directories: %s. This is an issue for the GraphQLite lib. Please make sure that a namespace can only be resolved to one PHP file.', $namespace, implode(", ", $possibleFileNames)));
94-
} elseif (empty($possibleFileNames)) {
95-
throw new \RuntimeException(sprintf('Files in namespace "%s" cannot be autoloaded by Composer. Please set up a PSR-4 autoloader in Composer or change the namespace configured in "graphqlite.namespace.controllers" and "graphqlite.namespace.types"', $namespace));
96-
}
97-
98-
return substr($possibleFileNames[0], 0, -8);
99-
}
100-
10197
/**
10298
* @param array<string, int> $debug
10399
* @return int

DependencyInjection/OverblogGraphiQLEndpointWiringPass.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace TheCodingMachine\Graphqlite\Bundle\DependencyInjection;
44

5-
use Overblog\GraphiQLBundle\Config\GraphiQLControllerEndpoint;
6-
use Overblog\GraphiQLBundle\Config\GraphqlEndpoint\RootResolver;
75
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
86
use Symfony\Component\DependencyInjection\ContainerBuilder;
97
use Symfony\Component\DependencyInjection\Definition;

GraphiQL/EndpointResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
namespace TheCodingMachine\Graphqlite\Bundle\GraphiQL;
44

55
use Overblog\GraphiQLBundle\Config\GraphiQLControllerEndpoint;
6+
use Overblog\GraphiQLBundle\Config\GraphQLEndpoint\GraphQLEndpointInvalidSchemaException;
67
use Symfony\Component\HttpFoundation\RequestStack;
8+
use Webmozart\Assert\Assert;
79

810
final class EndpointResolver implements GraphiQLControllerEndpoint
911
{
12+
/**
13+
* @var RequestStack
14+
*/
1015
protected $requestStack;
1116

1217
public function __construct(RequestStack $requestStack)
@@ -18,6 +23,7 @@ public function getBySchema($name)
1823
{
1924
if ('default' === $name) {
2025
$request = $this->requestStack->getCurrentRequest();
26+
Assert::notNull($request);
2127

2228
return $request->getBaseUrl().'/graphql';
2329
}

Mappers/RequestParameterMiddleware.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use phpDocumentor\Reflection\DocBlock;
88
use phpDocumentor\Reflection\Type;
9+
use ReflectionNamedType;
910
use ReflectionParameter;
1011
use Symfony\Component\HttpFoundation\Request;
1112
use TheCodingMachine\GraphQLite\Annotations\ParameterAnnotations;
@@ -15,13 +16,13 @@
1516

1617
class RequestParameterMiddleware implements ParameterMiddlewareInterface
1718
{
18-
1919
public function mapParameter(ReflectionParameter $parameter, DocBlock $docBlock, ?Type $paramTagType, ParameterAnnotations $parameterAnnotations, ParameterHandlerInterface $next): ParameterInterface
2020
{
2121
$parameterType = $parameter->getType();
22-
if ($parameterType && $parameterType->getName() === Request::class) {
22+
if ($parameterType instanceof ReflectionNamedType && $parameterType->getName() === Request::class) {
2323
return new RequestParameter();
2424
}
25+
2526
return $next->mapParameter($parameter, $docBlock, $paramTagType, $parameterAnnotations);
2627
}
2728
}

Server/ServerConfig.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
namespace TheCodingMachine\Graphqlite\Bundle\Server;
55

66
use GraphQL\Error\InvariantViolation;
7+
use GraphQL\GraphQL;
8+
use GraphQL\Language\AST\DocumentNode;
9+
use GraphQL\Server\OperationParams;
710
use GraphQL\Utils\Utils;
811
use GraphQL\Validator\DocumentValidator;
912
use GraphQL\Validator\Rules\ValidationRule;
@@ -27,7 +30,15 @@ class ServerConfig extends \GraphQL\Server\ServerConfig
2730
*/
2831
public function setValidationRules($validationRules)
2932
{
30-
parent::setValidationRules(array_merge(DocumentValidator::defaultRules(), $validationRules));
33+
parent::setValidationRules(
34+
function (OperationParams $params, DocumentNode $doc, string $operationType) use ($validationRules): array {
35+
$validationRules = is_callable($validationRules)
36+
? $validationRules($params, $doc, $operationType)
37+
: $validationRules;
38+
39+
return array_merge(DocumentValidator::defaultRules(), $validationRules);
40+
}
41+
);
3142

3243
return $this;
3344
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"php-coveralls/php-coveralls": "^2.1.0",
3939
"symfony/phpunit-bridge": "^5.3",
4040
"thecodingmachine/phpstan-strict-rules": "^v0.12.1",
41-
"composer/package-versions-deprecated": "^1.8"
41+
"composer/package-versions-deprecated": "^1.8",
42+
"phpstan/phpstan-webmozart-assert": "^0.12.12"
4243
},
4344
"conflict": {
4445
"mouf/classname-mapper": "<1.0.2",

phpstan.baseline.neon

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)