Completed
Pull Request — development (#673)
by Nick
12:54 queued 04:44
created

ErrorTrait::addError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\Util\Error;
4
5
trait ErrorTrait
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $errors = [];
11
12
    /**
13
     * @param string $text
14
     * @param null|string $context
15
     *
16
     * @return void
17
     */
18
    protected function addError($text, $context = null)
19
    {
20
        if ($context !== null) {
21
            $this->errors[$context] = $text;
22
23
            return;
24
        }
25
        $this->errors[] = $text;
26
    }
27
28
    /**
29
     * @return bool
30
     */
31
    public function hasErrors()
32
    {
33
        return count($this->errors) > 0;
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getErrors()
40
    {
41
        return $this->errors;
42
    }
43
}
44