Passed
Pull Request — master (#25)
by Quang
02:00
created

ExecutionResult   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getData() 0 3 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\Error\GraphQLError;
6
7
class ExecutionResult
8
{
9
    /**
10
     * @var GraphQLError[]
11
     */
12
    protected $errors;
13
14
    /**
15
     * @var mixed[]
16
     */
17
    protected $data;
18
19
    /**
20
     * ExecutionResult constructor.
21
     * @param mixed[] $data
22
     * @param GraphQLError[] $errors
23
     */
24
    public function __construct(array $data, array $errors)
25
    {
26
        $this->errors = $errors;
27
        $this->data   = $data;
28
    }
29
30
    /**
31
     * @return array|mixed[]
32
     */
33
    public function getData()
34
    {
35
        return $this->data;
36
    }
37
38
    /**
39
     * @return array|GraphQLError[]
40
     */
41
    public function getErrors(): array
42
    {
43
        return $this->errors;
44
    }
45
46
    /**
47
     * @param GraphQLError $error
48
     * @return ExecutionResult
49
     */
50
    public function addError(GraphQLError $error): ExecutionResult
51
    {
52
        $this->errors[] = $error;
53
        return $this;
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function toArray()
60
    {
61
        return [
62
            'data'   => $this->getData(),
63
            'errors' => $this->getErrors(),
64
        ];
65
    }
66
}
67