Completed
Push — master ( 2ab509...fc8247 )
by Quang
02:16
created

Execution::buildExecutionContext()   C

Complexity

Conditions 10
Paths 7

Size

Total Lines 52
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 29
nc 7
nop 7
dl 0
loc 52
rs 6.2553
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Digia\GraphQL\Execution;
4
5
use Digia\GraphQL\Error\GraphQLError;
6
use Digia\GraphQL\Language\AST\Node\DocumentNode;
7
use Digia\GraphQL\Language\AST\NodeKindEnum;
8
use Digia\GraphQL\Type\Schema;
9
use function Digia\GraphQL\Util\invariant;
10
11
/**
12
 * Class Execution
13
 * @package Digia\GraphQL\Execution
14
 */
15
class Execution
16
{
17
    /**
18
     * @var ExecutionContext
19
     */
20
    protected $context;
21
22
    /**
23
     * Execution constructor.
24
     * @param ExecutionContext $context
25
     */
26
    public function __construct(ExecutionContext $context)
27
    {
28
        $this->context = $context;
29
    }
30
31
    /**
32
     * @param Schema        $schema
33
     * @param DocumentNode  $documentNode
34
     * @param null          $rootValue
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $rootValue is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $variableValues is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $operationName is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $contextValue is correct as it would always require null to be passed?
Loading history...
35
     * @param null          $contextValue
36
     * @param null          $variableValues
37
     * @param null          $operationName
38
     * @param callable|null $fieldResolver
39
     * @return ExecutionResult
40
     */
41
    public static function execute(
42
        Schema $schema,
43
        DocumentNode $documentNode,
44
        $rootValue = null,
45
        $contextValue = null,
46
        $variableValues = [],
47
        $operationName = null,
48
        callable $fieldResolver = null
49
    ) {
50
        try {
51
            //@TODO Get context builder from container?
52
            $contextBuilder = new ExecutionContextBuilder();
53
54
            $context = $contextBuilder->buildContext(
55
                $schema,
56
                $documentNode,
57
                $rootValue,
58
                $contextValue,
59
                $variableValues,
60
                $operationName,
61
                $fieldResolver
62
            );
63
        } catch (GraphQLError $error) {
64
            return new ExecutionResult(['data' => null], [$error]);
65
        }
66
67
        $data = $context->getExecutionStrategy()->execute();
68
69
        return new ExecutionResult($data, $context->getErrors());
70
    }
71
}
72