We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
28 | class Executor |
||
29 | { |
||
30 | const PROMISE_ADAPTER_SERVICE_ID = 'overblog_graphql.promise_adapter'; |
||
31 | |||
32 | /** |
||
33 | * @var Schema[] |
||
34 | */ |
||
35 | private $schemas; |
||
36 | |||
37 | /** |
||
38 | * @var EventDispatcherInterface|null |
||
39 | */ |
||
40 | private $dispatcher; |
||
41 | |||
42 | /** @var bool */ |
||
43 | private $throwException; |
||
44 | |||
45 | /** @var ErrorHandler|null */ |
||
46 | private $errorHandler; |
||
47 | |||
48 | /** @var bool */ |
||
49 | private $hasDebugInfo; |
||
50 | |||
51 | /** |
||
52 | * @var ExecutorInterface |
||
53 | */ |
||
54 | private $executor; |
||
55 | |||
56 | /** |
||
57 | * @var PromiseAdapterInterface |
||
58 | */ |
||
59 | private $promiseAdapter; |
||
60 | |||
61 | 14 | public function __construct( |
|
76 | |||
77 | 2 | public function setExecutor(ExecutorInterface $executor) |
|
83 | |||
84 | 14 | public function addSchema($name, Schema $schema) |
|
90 | |||
91 | 1 | public function enabledDebugInfo() |
|
97 | |||
98 | 14 | public function disabledDebugInfo() |
|
104 | |||
105 | 46 | public function hasDebugInfo() |
|
109 | |||
110 | 9 | public function setMaxQueryDepth($maxQueryDepth) |
|
116 | |||
117 | 9 | public function setMaxQueryComplexity($maxQueryComplexity) |
|
123 | |||
124 | /** |
||
125 | * @param bool $throwException |
||
126 | * |
||
127 | * @return $this |
||
128 | */ |
||
129 | 25 | public function setThrowException($throwException) |
|
135 | |||
136 | 49 | public function execute(array $data, array $context = [], $schemaName = null) |
|
137 | { |
||
138 | 49 | if (null !== $this->dispatcher) { |
|
139 | 45 | $event = new ExecutorContextEvent($context); |
|
140 | 45 | $this->dispatcher->dispatch(Events::EXECUTOR_CONTEXT, $event); |
|
141 | 45 | $context = $event->getExecutorContext(); |
|
142 | 45 | } |
|
143 | |||
144 | 49 | $schema = $this->getSchema($schemaName); |
|
145 | |||
146 | 48 | $startTime = microtime(true); |
|
147 | 48 | $startMemoryUsage = memory_get_usage(true); |
|
148 | |||
149 | 48 | $this->executor->setPromiseAdapter($this->promiseAdapter); |
|
150 | |||
151 | 48 | $result = $this->executor->execute( |
|
152 | 48 | $schema, |
|
153 | 48 | isset($data[ParserInterface::PARAM_QUERY]) ? $data[ParserInterface::PARAM_QUERY] : null, |
|
154 | 48 | $context, |
|
155 | 48 | $context, |
|
156 | 48 | $data[ParserInterface::PARAM_VARIABLES], |
|
157 | 48 | isset($data[ParserInterface::PARAM_OPERATION_NAME]) ? $data[ParserInterface::PARAM_OPERATION_NAME] : null |
|
158 | 48 | ); |
|
159 | |||
160 | 48 | if (!is_object($result) || (!$result instanceof ExecutionResult && !$result instanceof Promise)) { |
|
161 | 2 | throw new \RuntimeException( |
|
162 | 2 | sprintf( |
|
163 | 2 | 'Execution result should be an object instantiating "%s" or "%s".', |
|
164 | 2 | 'GraphQL\\Executor\\ExecutionResult', |
|
165 | 'GraphQL\\Executor\\Promise\\Promise' |
||
166 | 2 | ) |
|
167 | 2 | ); |
|
168 | } |
||
169 | |||
170 | 46 | if ($this->promiseAdapter && $this->promiseAdapter->isThenable($result)) { |
|
171 | 10 | $result = $this->promiseAdapter->wait($result); |
|
|
|||
172 | 10 | } |
|
173 | |||
174 | 46 | return $this->prepareResult($result, $startTime, $startMemoryUsage); |
|
175 | } |
||
176 | |||
177 | 46 | private function prepareResult($result, $startTime, $startMemoryUsage) |
|
192 | |||
193 | /** |
||
194 | * @param string|null $name |
||
195 | * |
||
196 | * @return Schema |
||
197 | */ |
||
198 | 50 | public function getSchema($name = null) |
|
215 | } |
||
216 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.