Completed
Pull Request — master (#15)
by Christoffer
03:26
created

ExecutionResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getErrors() 0 3 1
A addError() 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
     * @return array|GraphQLError[]
35
     */
36
    public function getErrors(): array
37
    {
38
        return $this->errors;
39
    }
40
41
    /**
42
     * @param GraphQLError $error
43
     * @return ExecutionResult
44
     */
45
    public function addError(GraphQLError $error): ExecutionResult
46
    {
47
        $this->errors[] = $error;
48
        return $this;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function toArray(): array
55
    {
56
        return [
57
            'data'   => $this->data,
58
            'errors' => $this->errors,
59
        ];
60
    }
61
}
62