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
Pull Request — master (#21)
by Jérémiah
08:59
created

Executor::execute()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 22
ccs 17
cts 17
cp 1
rs 8.9197
cc 4
eloc 14
nc 4
nop 2
crap 4
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Request;
13
14
use GraphQL\Error;
15
use GraphQL\Executor\ExecutionResult;
16
use GraphQL\Executor\Executor as GraphQLExecutor;
17
use GraphQL\GraphQL;
18
use GraphQL\Language\Parser as GraphQLParser;
19
use GraphQL\Language\Source;
20
use GraphQL\Schema;
21
use GraphQL\Validator\DocumentValidator;
22
use Overblog\GraphQLBundle\Error\ErrorHandler;
23
use Overblog\GraphQLBundle\Event\Events;
24
use Overblog\GraphQLBundle\Event\ExecutorContextEvent;
25
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
26
27
class Executor
28
{
29
    private $schema;
30
31
    /**
32
     * @var EventDispatcherInterface|null
33
     */
34
    private $dispatcher;
35
36
    /** @var bool */
37
    private $throwException;
38
39
    /** @var ErrorHandler|null */
40
    private $errorHandler;
41
42
    /** @var callable[] */
43
    private $validationRules;
44
45 27
    public function __construct(Schema $schema, EventDispatcherInterface $dispatcher = null, $throwException = false, ErrorHandler $errorHandler = null)
46
    {
47 27
        $this->schema = $schema;
48 27
        $this->dispatcher = $dispatcher;
49 27
        $this->throwException = (bool) $throwException;
50 27
        $this->errorHandler = $errorHandler;
51 27
        $this->validationRules = DocumentValidator::allRules();
52 27
    }
53
54 27
    public function addValidatorRule(callable $validatorRule)
55 1
    {
56 27
        $this->validationRules[] = $validatorRule;
57 27
    }
58
59
    /**
60
     * @param bool $throwException
61
     *
62
     * @return $this
63
     */
64 23
    public function setThrowException($throwException)
65
    {
66 23
        $this->throwException = (bool) $throwException;
67
68 23
        return $this;
69 1
    }
70
71 27
    public function execute(array $data, array $context = [])
72
    {
73 27
        if (null !== $this->dispatcher) {
74 27
            $event = new ExecutorContextEvent($context);
75 27
            $this->dispatcher->dispatch(Events::EXECUTOR_CONTEXT, $event);
76 27
            $context = $event->getExecutorContext();
77 27
        }
78
79 27
        $executionResult = $this->executeAndReturnResult(
80 27
            $this->schema,
81 27
            isset($data['query']) ? $data['query'] : null,
82 27
            $context,
83 27
            $data['variables'],
84 27
            $data['operationName']
85 27
        );
86
87 27
        if (null !== $this->errorHandler) {
88 27
            $this->errorHandler->handleErrors($executionResult, $this->throwException);
89 27
        }
90
91 27
        return $executionResult;
92
    }
93
94 27
    private function executeAndReturnResult(Schema $schema, $requestString, $rootValue = null, $variableValues = null, $operationName = null)
95
    {
96
        try {
97 27
            $source = new Source($requestString ?: '', 'GraphQL request');
98 27
            $documentAST = GraphQLParser::parse($source);
99 27
            $validationErrors = DocumentValidator::validate($schema, $documentAST, $this->validationRules);
100
101 27
            if (!empty($validationErrors)) {
102 1
                return new ExecutionResult(null, $validationErrors);
103
            }
104
105 26
            return GraphQLExecutor::execute($schema, $documentAST, $rootValue, $variableValues, $operationName);
106
        } catch (Error $e) {
107
            return new ExecutionResult(null, [$e]);
108
        }
109
    }
110
}
111