Completed
Pull Request — master (#15)
by Christoffer
03:18 queued 01:12
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
     * @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