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 — master ( bb0ab9...03ca69 )
by Jérémiah
20:24 queued 44s
created

Executor   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 15
eloc 62
dl 0
loc 160
ccs 66
cts 69
cp 0.9565
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A addSchema() 0 5 1
A disableIntrospectionQuery() 0 3 1
A postExecute() 0 6 1
A setMaxQueryComplexity() 0 5 1
A execute() 0 29 2
A setMaxQueryDepth() 0 5 1
A __construct() 0 12 1
A preExecute() 0 16 1
A setExecutor() 0 5 1
A enableIntrospectionQuery() 0 3 1
A getSchema() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Request;
6
7
use GraphQL\Executor\ExecutionResult;
8
use GraphQL\Executor\Promise\PromiseAdapter;
9
use GraphQL\GraphQL;
10
use GraphQL\Type\Schema;
11
use GraphQL\Validator\DocumentValidator;
12
use GraphQL\Validator\Rules\DisableIntrospection;
13
use GraphQL\Validator\Rules\QueryComplexity;
14
use GraphQL\Validator\Rules\QueryDepth;
15
use Overblog\GraphQLBundle\Event\Events;
16
use Overblog\GraphQLBundle\Event\ExecutorArgumentsEvent;
17
use Overblog\GraphQLBundle\Event\ExecutorContextEvent;
18
use Overblog\GraphQLBundle\Event\ExecutorResultEvent;
19
use Overblog\GraphQLBundle\Executor\ExecutorInterface;
20
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
21
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
22
23
class Executor
24
{
25
    public const PROMISE_ADAPTER_SERVICE_ID = 'overblog_graphql.promise_adapter';
26
27
    private $schemas = [];
28
29
    private $dispatcher;
30
31
    private $promiseAdapter;
32
33
    private $executor;
34
35
    private $defaultFieldResolver;
36
37
    private $useExperimentalExecutor;
38
39 104
    public function __construct(
40
        ExecutorInterface $executor,
41
        PromiseAdapter $promiseAdapter,
42
        EventDispatcherInterface $dispatcher,
43
        ?callable $defaultFieldResolver = null,
44
        bool $useExperimental = false
45
    ) {
46 104
        $this->executor = $executor;
47 104
        $this->promiseAdapter = $promiseAdapter;
48 104
        $this->dispatcher = $dispatcher;
49 104
        $this->defaultFieldResolver = $defaultFieldResolver;
50 104
        $this->useExperimentalExecutor = $useExperimental;
51 104
    }
52
53
    public function setExecutor(ExecutorInterface $executor): self
54
    {
55
        $this->executor = $executor;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @param string $name
62
     * @param Schema $schema
63
     *
64
     * @return self
65
     */
66 95
    public function addSchema(string $name, Schema $schema): self
67
    {
68 95
        $this->schemas[$name] = $schema;
69
70 95
        return $this;
71
    }
72
73
    /**
74
     * @param string|null $name
75
     *
76
     * @return Schema
77
     */
78 89
    public function getSchema(?string $name = null): Schema
79
    {
80 89
        if (empty($this->schemas)) {
81 1
            throw new \RuntimeException('At least one schema should be declare.');
82
        }
83
84 88
        if (null === $name) {
85 82
            $schema = \array_values($this->schemas)[0];
86
        } else {
87 6
            if (!isset($this->schemas[$name])) {
88 1
                throw new NotFoundHttpException(\sprintf('Could not found "%s" schema.', $name));
89
            }
90 5
            $schema = $this->schemas[$name];
91
        }
92
93 87
        return $schema;
94
    }
95
96 103
    public function setMaxQueryDepth($maxQueryDepth): void
97
    {
98
        /** @var QueryDepth $queryDepth */
99 103
        $queryDepth = DocumentValidator::getRule('QueryDepth');
100 103
        $queryDepth->setMaxQueryDepth($maxQueryDepth);
101 103
    }
102
103 103
    public function setMaxQueryComplexity($maxQueryComplexity): void
104
    {
105
        /** @var QueryComplexity $queryComplexity */
106 103
        $queryComplexity = DocumentValidator::getRule('QueryComplexity');
107 103
        $queryComplexity->setMaxQueryComplexity($maxQueryComplexity);
108 103
    }
109
110 101
    public function enableIntrospectionQuery(): void
111
    {
112 101
        DocumentValidator::addRule(new DisableIntrospection(DisableIntrospection::DISABLED));
113 101
    }
114
115 1
    public function disableIntrospectionQuery(): void
116
    {
117 1
        DocumentValidator::addRule(new DisableIntrospection());
118 1
    }
119
120
    /**
121
     * @param string|null                    $schemaName
122
     * @param array                          $request
123
     * @param array|\ArrayObject|object|null $rootValue
124
     *
125
     * @return ExecutionResult
126
     */
127 85
    public function execute(?string $schemaName, array $request, $rootValue = null): ExecutionResult
128
    {
129 85
        $this->useExperimentalExecutor ? GraphQL::useExperimentalExecutor() : GraphQL::useReferenceExecutor();
130
131 85
        $executorArgumentsEvent = $this->preExecute(
132 85
            $this->getSchema($schemaName),
133 84
            $request[ParserInterface::PARAM_QUERY] ?? null,
134 84
            new \ArrayObject(),
135 84
            $rootValue,
136 84
            $request[ParserInterface::PARAM_VARIABLES],
137 84
            $request[ParserInterface::PARAM_OPERATION_NAME] ?? null
138
        );
139
140 84
        $executorArgumentsEvent->getSchema()->processExtensions();
141
142 84
        $result = $this->executor->execute(
143 84
            $this->promiseAdapter,
144 84
            $executorArgumentsEvent->getSchema(),
145 84
            $executorArgumentsEvent->getRequestString(),
146 84
            $executorArgumentsEvent->getRootValue(),
147 84
            $executorArgumentsEvent->getContextValue(),
0 ignored issues
show
Bug introduced by
$executorArgumentsEvent->getContextValue() of type ArrayObject is incompatible with the type array|null expected by parameter $contextValue of Overblog\GraphQLBundle\E...torInterface::execute(). ( Ignorable by Annotation )

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

147
            /** @scrutinizer ignore-type */ $executorArgumentsEvent->getContextValue(),
Loading history...
148 84
            $executorArgumentsEvent->getVariableValue(),
149 84
            $executorArgumentsEvent->getOperationName(),
150 84
            $this->defaultFieldResolver
151
        );
152
153 84
        $result = $this->postExecute($result);
154
155 83
        return $result;
156
    }
157
158 84
    private function preExecute(
159
        Schema $schema,
160
        ?string $requestString,
161
        \ArrayObject $contextValue,
162
        $rootValue = null,
163
        ?array $variableValue = null,
164
        ?string $operationName = null
165
    ): ExecutorArgumentsEvent {
166 84
        $this->dispatcher->dispatch(
167 84
            new ExecutorContextEvent($contextValue),
168 84
            Events::EXECUTOR_CONTEXT
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with Overblog\GraphQLBundle\E...vents::EXECUTOR_CONTEXT. ( Ignorable by Annotation )

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

168
        $this->dispatcher->/** @scrutinizer ignore-call */ 
169
                           dispatch(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
169
        );
170
171 84
        return $this->dispatcher->dispatch(
172 84
            ExecutorArgumentsEvent::create($schema, $requestString, $contextValue, $rootValue, $variableValue, $operationName),
173 84
            Events::PRE_EXECUTOR
174
        );
175
    }
176
177 84
    private function postExecute(ExecutionResult $result): ExecutionResult
178
    {
179 84
        return $this->dispatcher->dispatch(
180 84
            new ExecutorResultEvent($result),
181 84
            Events::POST_EXECUTOR
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with Overblog\GraphQLBundle\Event\Events::POST_EXECUTOR. ( Ignorable by Annotation )

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

181
        return $this->dispatcher->/** @scrutinizer ignore-call */ dispatch(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
182 83
        )->getResult();
183
    }
184
}
185