From 330ff148e014041df16ab82d8b461d1d453d306f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 11 May 2020 15:06:07 +0200 Subject: [PATCH] Upgrading code to PHPStan 0.12 --- Controller/GraphQL/InvalidUserPasswordException.php | 2 +- Controller/GraphqliteController.php | 1 + DependencyInjection/GraphqliteCompilerPass.php | 13 ++++++++++--- DependencyInjection/GraphqliteExtension.php | 9 +++++++-- .../OverblogGraphiQLEndpointWiringPass.php | 3 +-- GraphqliteBundle.php | 2 +- composer.json | 2 +- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Controller/GraphQL/InvalidUserPasswordException.php b/Controller/GraphQL/InvalidUserPasswordException.php index 9d21d79..6a4379f 100644 --- a/Controller/GraphQL/InvalidUserPasswordException.php +++ b/Controller/GraphQL/InvalidUserPasswordException.php @@ -8,7 +8,7 @@ class InvalidUserPasswordException extends GraphQLException { - public static function create(Exception $previous = null) + public static function create(Exception $previous = null): self { return new self('The provided user / password is incorrect.', 401, $previous, 'Security'); } diff --git a/Controller/GraphqliteController.php b/Controller/GraphqliteController.php index 0c888e8..1316201 100644 --- a/Controller/GraphqliteController.php +++ b/Controller/GraphqliteController.php @@ -114,6 +114,7 @@ private function handlePsr7Request(ServerRequestInterface $request, Request $sym if ($result instanceof Promise) { throw new RuntimeException('Only SyncPromiseAdapter is supported'); } + /* @phpstan-ignore-next-line */ throw new RuntimeException('Unexpected response from StandardServer::executePsrRequest'); // @codeCoverageIgnore } } diff --git a/DependencyInjection/GraphqliteCompilerPass.php b/DependencyInjection/GraphqliteCompilerPass.php index c0163ce..dab425f 100644 --- a/DependencyInjection/GraphqliteCompilerPass.php +++ b/DependencyInjection/GraphqliteCompilerPass.php @@ -3,6 +3,7 @@ namespace TheCodingMachine\Graphqlite\Bundle\DependencyInjection; +use ReflectionNamedType; use Symfony\Component\Cache\Adapter\ApcuAdapter; use Symfony\Component\Cache\Adapter\PhpFilesAdapter; use Symfony\Component\Cache\Psr16Cache; @@ -85,7 +86,7 @@ class GraphqliteCompilerPass implements CompilerPassInterface /** * You can modify the container here before it is dumped to PHP code. */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $reader = $this->getAnnotationReader(); //$inputTypeUtils = new InputTypeUtils($reader, $namingStrategy); @@ -175,6 +176,9 @@ public function process(ContainerBuilder $container) if ($definition->isAbstract() || $definition->getClass() === null) { continue; } + /** + * @var class-string $class + */ $class = $definition->getClass(); /* foreach ($controllersNamespaces as $controllersNamespace) { if (strpos($class, $controllersNamespace) === 0) { @@ -287,6 +291,9 @@ private function mapAdderToTag(string $tag, string $methodName, ContainerBuilder } } + /** + * @param ReflectionClass $refClass + */ private function makePublicInjectedServices(ReflectionClass $refClass, AnnotationReader $reader, ContainerBuilder $container, bool $isController): void { $services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController) { @@ -349,7 +356,7 @@ private function getListOfInjectedServices(ReflectionMethod $method, ContainerBu } else { $parameter = $parametersByName[$target]; $type = $parameter->getType(); - if ($type !== null) { + if ($type !== null && $type instanceof ReflectionNamedType) { $fqcn = $type->getName(); if ($container->has($fqcn)) { $services[$fqcn] = $fqcn; @@ -427,7 +434,7 @@ private function getCodeCache(): ClassBoundCacheContractInterface * Returns the array of globbed classes. * Only instantiable classes are returned. * - * @return array Key: fully qualified class name + * @return array> Key: fully qualified class name */ private function getClassList(string $namespace, int $globTtl = 2, bool $recursive = true): array { diff --git a/DependencyInjection/GraphqliteExtension.php b/DependencyInjection/GraphqliteExtension.php index 1ac10f9..d844f25 100644 --- a/DependencyInjection/GraphqliteExtension.php +++ b/DependencyInjection/GraphqliteExtension.php @@ -27,9 +27,10 @@ class GraphqliteExtension extends Extension /** * Loads a specific configuration. * - * @throws \InvalidArgumentException When provided tag is not defined in this extension + * @param mixed[] $configs + * @throws \Exception */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); @@ -94,6 +95,10 @@ private function getNamespaceDir(string $namespace): string return substr($possibleFileNames[0], 0, -8); } + /** + * @param array $debug + * @return int + */ private function toDebugCode(array $debug): int { $code = 0; diff --git a/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php b/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php index 4ec7f20..43df7ef 100644 --- a/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php +++ b/DependencyInjection/OverblogGraphiQLEndpointWiringPass.php @@ -13,12 +13,11 @@ final class OverblogGraphiQLEndpointWiringPass implements CompilerPassInterface { //@todo https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Tests/Compiler/RemoveUnusedDefinitionsPassTest.php - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $endPointDefinition = new Definition(EndpointResolver::class); $endPointDefinition->addArgument(new Reference('request_stack')); $container->setDefinition('overblog_graphiql.controller.graphql.endpoint', $endPointDefinition); - } } diff --git a/GraphqliteBundle.php b/GraphqliteBundle.php index e584bbe..3a15b49 100644 --- a/GraphqliteBundle.php +++ b/GraphqliteBundle.php @@ -11,7 +11,7 @@ class GraphqliteBundle extends Bundle { - public function build(ContainerBuilder $container) + public function build(ContainerBuilder $container): void { parent::build($container); diff --git a/composer.json b/composer.json index d955d26..6f54c1b 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "symfony/security-bundle": "^4.1.9 | ^5", "symfony/yaml": "^4.1.9 | ^5", "phpunit/phpunit": "^7.5.1", - "phpstan/phpstan-shim": "^0.11.19", + "phpstan/phpstan": "^0.12.25", "beberlei/porpaginas": "^1.2", "php-coveralls/php-coveralls": "^2.1.0" },