Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — 0.12 ( 247c91...94418a )
by Jérémiah
24:10 queued 24:06
created

SchemaBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Definition\Builder;
6
7
use GraphQL\Type\Definition\Type;
8
use Overblog\GraphQLBundle\Definition\Type\ExtensibleSchema;
9
use Overblog\GraphQLBundle\Definition\Type\SchemaExtension\ValidatorExtension;
10
use Overblog\GraphQLBundle\Resolver\TypeResolver;
11
12
class SchemaBuilder
13
{
14
    /** @var TypeResolver */
15
    private $typeResolver;
16
17
    /** @var bool */
18
    private $enableValidation;
19
20 96
    public function __construct(TypeResolver $typeResolver, bool $enableValidation = false)
21
    {
22 96
        $this->typeResolver = $typeResolver;
23 96
        $this->enableValidation = $enableValidation;
24 96
    }
25
26 96
    public function getBuilder(string  $name, ?string $queryAlias, ?string $mutationAlias = null, ?string $subscriptionAlias = null, array $types = []): callable
27
    {
28
        return function () use ($name, $queryAlias, $mutationAlias, $subscriptionAlias, $types): ExtensibleSchema {
29 88
            static $schema = null;
30 88
            if (null === $schema) {
31 88
                $schema = $this->create($name, $queryAlias, $mutationAlias, $subscriptionAlias, $types);
32
            }
33
34 87
            return $schema;
35 96
        };
36
    }
37
38
    /**
39
     * @param string      $name
40
     * @param string|null $queryAlias
41
     * @param string|null $mutationAlias
42
     * @param string|null $subscriptionAlias
43
     * @param string[]    $types
44
     *
45
     * @return ExtensibleSchema
46
     */
47 88
    public function create(string  $name, ?string $queryAlias, ?string $mutationAlias = null, ?string $subscriptionAlias = null, array $types = []): ExtensibleSchema
48
    {
49 88
        $this->typeResolver->setCurrentSchemaName($name);
50 88
        $query = $this->typeResolver->resolve($queryAlias);
51 87
        $mutation = $this->typeResolver->resolve($mutationAlias);
52 87
        $subscription = $this->typeResolver->resolve($subscriptionAlias);
53
54 87
        $schema = new ExtensibleSchema($this->buildSchemaArguments($name, $query, $mutation, $subscription, $types));
0 ignored issues
show
Bug introduced by
It seems like $query can also be of type null; however, parameter $query of Overblog\GraphQLBundle\D...:buildSchemaArguments() does only seem to accept GraphQL\Type\Definition\Type, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
        $schema = new ExtensibleSchema($this->buildSchemaArguments($name, /** @scrutinizer ignore-type */ $query, $mutation, $subscription, $types));
Loading history...
55 87
        $extensions = [];
56
57 87
        if ($this->enableValidation) {
58 81
            $extensions[] = new ValidatorExtension();
59
        }
60 87
        $schema->setExtensions($extensions);
61
62 87
        return $schema;
63
    }
64
65 87
    private function buildSchemaArguments(string $schemaName, Type $query, ?Type $mutation, ?Type $subscription, array $types = []): array
66
    {
67
        return [
68 87
            'query' => $query,
69 87
            'mutation' => $mutation,
70 87
            'subscription' => $subscription,
71
            'typeLoader' => function ($name) use ($schemaName) {
72 86
                $this->typeResolver->setCurrentSchemaName($schemaName);
73
74 86
                return $this->typeResolver->resolve($name);
75 87
            },
76
            'types' => function () use ($types, $schemaName) {
77 85
                $this->typeResolver->setCurrentSchemaName($schemaName);
78
79 85
                return \array_map([$this->typeResolver, 'resolve'], $types);
80 87
            },
81
        ];
82
    }
83
}
84