Skip to content

Upgrading code to PHPStan 0.12 #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Controller/GraphQL/InvalidUserPasswordException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
1 change: 1 addition & 0 deletions Controller/GraphqliteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
13 changes: 10 additions & 3 deletions DependencyInjection/GraphqliteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -287,6 +291,9 @@ private function mapAdderToTag(string $tag, string $methodName, ContainerBuilder
}
}

/**
* @param ReflectionClass<object> $refClass
*/
private function makePublicInjectedServices(ReflectionClass $refClass, AnnotationReader $reader, ContainerBuilder $container, bool $isController): void
{
$services = $this->getCodeCache()->get($refClass, function() use ($refClass, $reader, $container, $isController) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -427,7 +434,7 @@ private function getCodeCache(): ClassBoundCacheContractInterface
* Returns the array of globbed classes.
* Only instantiable classes are returned.
*
* @return array<string,ReflectionClass> Key: fully qualified class name
* @return array<string,ReflectionClass<object>> Key: fully qualified class name
*/
private function getClassList(string $namespace, int $globTtl = 2, bool $recursive = true): array
{
Expand Down
9 changes: 7 additions & 2 deletions DependencyInjection/GraphqliteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -94,6 +95,10 @@ private function getNamespaceDir(string $namespace): string
return substr($possibleFileNames[0], 0, -8);
}

/**
* @param array<string, int> $debug
* @return int
*/
private function toDebugCode(array $debug): int
{
$code = 0;
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/OverblogGraphiQLEndpointWiringPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
2 changes: 1 addition & 1 deletion GraphqliteBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class GraphqliteBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down