Completed
Push — master ( 120e4f...bd44b4 )
by Portey
07:04
created

ErrorContainerTrait::getErrorsArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4286
cc 3
eloc 5
nc 3
nop 0
crap 3
1
<?php
2
/**
3
 * Date: 01.12.15
4
 *
5
 * @author Portey Vasil <[email protected]>
6
 */
7
8
namespace Youshido\GraphQL\Validator\ErrorContainer;
9
10
11
trait ErrorContainerTrait
12
{
13
14
    /** @var \Exception[] */
15
    protected $errors = [];
16
17 2
    public function addError(\Exception $exception)
18
    {
19 2
        $this->errors[] = $exception;
20 2
    }
21
22 22
    public function hasErrors()
23
    {
24 22
        return !empty($this->errors);
25
    }
26
27
    public function getErrors()
28
    {
29
        return $this->errors;
30
    }
31
32 2
    public function getErrorsArray()
33
    {
34 2
        $errors = [];
35
36 2
        foreach ($this->errors as $error) {
37 2
            $errors[] = is_object($error) ? $error->getMessage() : $error;
38 2
        }
39
40 2
        return $errors;
41
    }
42
43 13
    public function clearErrors()
44
    {
45 13
        $this->errors = [];
46
47 13
        return $this;
48
    }
49
50
}