Completed
Pull Request — master (#15)
by Christoffer
03:18 queued 01:12
created

ExecutionResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addError() 0 4 1
A __construct() 0 4 1
A toArray() 0 5 1
1
<?php
2
3
namespace Digia\GraphQL\Execution;
4
5
use Digia\GraphQL\Contract\SerializationInterface;
6
use Digia\GraphQL\Error\GraphQLError;
7
8
class ExecutionResult implements SerializationInterface
9
{
10
11
    /**
12
     * @var GraphQLError[]
13
     */
14
    protected $errors;
15
16
    /**
17
     * @var mixed[]
18
     */
19
    protected $data;
20
21
    /**
22
     * ExecutionResult constructor.
23
     *
24
     * @param mixed[]        $data
25
     * @param GraphQLError[] $errors
26
     */
27
    public function __construct(?array $data, ?array $errors)
28
    {
29
        $this->errors = $errors;
30
        $this->data   = $data;
31
    }
32
33
    /**
34
     * @param GraphQLError $error
35
     * @return ExecutionResult
36
     */
37
    public function addError(GraphQLError $error): ExecutionResult
38
    {
39
        $this->errors[] = $error;
40
        return $this;
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function toArray(): array
47
    {
48
        return [
49
            'data'   => $this->data,
50
            'errors' => $this->errors,
51
        ];
52
    }
53
}
54