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

ExecutionResult::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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