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

ErrorContainerTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 40
ccs 14
cts 16
cp 0.875
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addError() 0 4 1
A hasErrors() 0 4 1
A getErrors() 0 4 1
A getErrorsArray() 0 10 3
A clearErrors() 0 6 1
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
}