We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 22 | class Executor |
||
| 23 | { |
||
| 24 | const PROMISE_ADAPTER_SERVICE_ID = 'overblog_graphql.promise_adapter'; |
||
| 25 | |||
| 26 | /** @var Schema[] */ |
||
| 27 | private $schemas = []; |
||
| 28 | |||
| 29 | /** @var EventDispatcherInterface|null */ |
||
| 30 | private $dispatcher; |
||
| 31 | |||
| 32 | /** @var ExecutorInterface */ |
||
| 33 | private $executor; |
||
| 34 | |||
| 35 | /** @var PromiseAdapter */ |
||
| 36 | private $promiseAdapter; |
||
| 37 | |||
| 38 | /** @var callable|null */ |
||
| 39 | private $defaultFieldResolver; |
||
| 40 | |||
| 41 | 4 | public function __construct( |
|
| 52 | |||
| 53 | 2 | public function setExecutor(ExecutorInterface $executor) |
|
| 59 | |||
| 60 | 1 | public function setPromiseAdapter(PromiseAdapter $promiseAdapter) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $name |
||
| 69 | * @param Schema $schema |
||
| 70 | * |
||
| 71 | * @return $this |
||
| 72 | */ |
||
| 73 | 4 | public function addSchema($name, Schema $schema) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @param string|null $name |
||
| 82 | * |
||
| 83 | * @return Schema |
||
| 84 | */ |
||
| 85 | 4 | public function getSchema($name = null) |
|
| 86 | { |
||
| 87 | 4 | if (empty($this->schemas)) { |
|
| 88 | 1 | throw new \RuntimeException('At least one schema should be declare.'); |
|
| 89 | } |
||
| 90 | |||
| 91 | 3 | if (null === $name) { |
|
| 92 | 3 | $schema = array_values($this->schemas)[0]; |
|
| 93 | } else { |
||
| 94 | if (!isset($this->schemas[$name])) { |
||
| 95 | throw new NotFoundHttpException(sprintf('Could not found "%s" schema.', $name)); |
||
| 96 | } |
||
| 97 | $schema = $this->schemas[$name]; |
||
| 98 | } |
||
| 99 | |||
| 100 | 3 | return $schema; |
|
| 101 | } |
||
| 102 | |||
| 103 | public function setMaxQueryDepth($maxQueryDepth) |
||
| 104 | { |
||
| 105 | /** @var QueryDepth $queryDepth */ |
||
| 106 | $queryDepth = DocumentValidator::getRule('QueryDepth'); |
||
| 107 | $queryDepth->setMaxQueryDepth($maxQueryDepth); |
||
| 108 | } |
||
| 109 | |||
| 110 | public function setMaxQueryComplexity($maxQueryComplexity) |
||
| 111 | { |
||
| 112 | /** @var QueryComplexity $queryComplexity */ |
||
| 113 | $queryComplexity = DocumentValidator::getRule('QueryComplexity'); |
||
| 114 | $queryComplexity->setMaxQueryComplexity($maxQueryComplexity); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function disableIntrospectionQuery() |
||
| 118 | { |
||
| 119 | DocumentValidator::addRule(new DisableIntrospection()); |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param null|string $schemaName |
||
| 124 | * @param array $request |
||
| 125 | * @param null|array|\ArrayObject|object $rootValue |
||
| 126 | * |
||
| 127 | * @return ExecutionResult |
||
| 128 | */ |
||
| 129 | 3 | public function execute($schemaName, array $request, $rootValue = null) |
|
| 130 | { |
||
| 131 | 3 | $executorArgumentsEvent = $this->preExecute( |
|
| 132 | 3 | $this->getSchema($schemaName), |
|
| 133 | 3 | isset($request[ParserInterface::PARAM_QUERY]) ? $request[ParserInterface::PARAM_QUERY] : null, |
|
| 134 | 3 | new \ArrayObject(), |
|
| 135 | 3 | $rootValue, |
|
| 136 | 3 | $request[ParserInterface::PARAM_VARIABLES], |
|
| 137 | 3 | isset($request[ParserInterface::PARAM_OPERATION_NAME]) ? $request[ParserInterface::PARAM_OPERATION_NAME] : null |
|
| 138 | ); |
||
| 139 | |||
| 140 | 2 | $executorArgumentsEvent->getSchema()->processExtensions(); |
|
| 141 | |||
| 142 | 2 | $result = $this->executor->execute( |
|
| 143 | 2 | $executorArgumentsEvent->getSchema(), |
|
| 144 | 2 | $executorArgumentsEvent->getRequestString(), |
|
| 145 | 2 | $executorArgumentsEvent->getRootValue(), |
|
| 146 | 2 | $executorArgumentsEvent->getContextValue(), |
|
|
|
|||
| 147 | 2 | $executorArgumentsEvent->getVariableValue(), |
|
| 148 | 2 | $executorArgumentsEvent->getOperationName() |
|
| 149 | ); |
||
| 150 | |||
| 151 | 2 | $result = $this->postExecute($result); |
|
| 152 | |||
| 153 | return $result; |
||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param Schema $schema |
||
| 158 | * @param string $requestString |
||
| 159 | * @param \ArrayObject $contextValue |
||
| 160 | * @param mixed $rootValue |
||
| 161 | * @param array|null $variableValue |
||
| 162 | * @param string|null $operationName |
||
| 163 | * |
||
| 164 | * @return ExecutorArgumentsEvent |
||
| 165 | */ |
||
| 166 | 3 | private function preExecute( |
|
| 167 | Schema $schema, |
||
| 168 | $requestString, |
||
| 169 | \ArrayObject $contextValue, |
||
| 170 | $rootValue = null, |
||
| 171 | array $variableValue = null, |
||
| 172 | $operationName = null |
||
| 173 | ) { |
||
| 174 | 3 | $this->checkPromiseAdapter(); |
|
| 175 | |||
| 176 | 2 | $this->executor->setPromiseAdapter($this->promiseAdapter); |
|
| 177 | // this is needed when not using only generated types |
||
| 178 | 2 | if ($this->defaultFieldResolver) { |
|
| 179 | $this->executor->setDefaultFieldResolver($this->defaultFieldResolver); |
||
| 180 | } |
||
| 181 | 2 | $this->dispatcher->dispatch(Events::EXECUTOR_CONTEXT, new ExecutorContextEvent($contextValue)); |
|
| 182 | |||
| 183 | 2 | return $this->dispatcher->dispatch( |
|
| 184 | 2 | Events::PRE_EXECUTOR, |
|
| 185 | 2 | ExecutorArgumentsEvent::create($schema, $requestString, $contextValue, $rootValue, $variableValue, $operationName) |
|
| 186 | ); |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param ExecutionResult|Promise $result |
||
| 191 | * |
||
| 192 | * @return ExecutionResult |
||
| 193 | */ |
||
| 194 | 2 | private function postExecute($result) |
|
| 195 | { |
||
| 196 | 2 | if ($result instanceof Promise) { |
|
| 197 | $result = $this->promiseAdapter->wait($result); |
||
| 198 | } |
||
| 199 | |||
| 200 | 2 | $this->checkExecutionResult($result); |
|
| 201 | |||
| 202 | return $this->dispatcher->dispatch(Events::POST_EXECUTOR, new ExecutorResultEvent($result))->getResult(); |
||
| 203 | } |
||
| 204 | |||
| 205 | 3 | private function checkPromiseAdapter() |
|
| 217 | |||
| 218 | 2 | private function checkExecutionResult($result) |
|
| 219 | { |
||
| 220 | 2 | if (!is_object($result) || !$result instanceof ExecutionResult) { |
|
| 221 | 2 | throw new \RuntimeException( |
|
| 222 | 2 | sprintf('Execution result should be an object instantiating "%s".', ExecutionResult::class) |
|
| 223 | ); |
||
| 224 | } |
||
| 226 | } |
||
| 227 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: