ErrorObject   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resetErrors() 0 3 1
A hasErrors() 0 3 1
A addError() 0 3 1
A getErrors() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of byrokrat\autogiro.
5
 *
6
 * byrokrat\autogiro is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * byrokrat\autogiro is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with byrokrat\autogiro. If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Copyright 2016-21 Hannes Forsgård
20
 */
21
22
declare(strict_types=1);
23
24
namespace byrokrat\autogiro\Visitor;
25
26
/**
27
 * Container of error messages
28
 */
29
class ErrorObject
30
{
31
    /**
32
     * @var string[] List of messages describing found errors
33
     */
34
    private $errors = [];
35
36
    /**
37
     * Check if any errors have been found
38
     */
39
    public function hasErrors(): bool
40
    {
41
        return !empty($this->getErrors());
42
    }
43
44
    /**
45
     * Get list of messages describing found errors
46
     *
47
     * @return string[]
48
     */
49
    public function getErrors(): array
50
    {
51
        return $this->errors;
52
    }
53
54
    /**
55
     * Add error message to store
56
     */
57
    public function addError(string $msg, string ...$args): void
58
    {
59
        $this->errors[] = sprintf($msg, ...$args);
60
    }
61
62
    /**
63
     * Reset error store
64
     */
65
    public function resetErrors(): void
66
    {
67
        $this->errors = [];
68
    }
69
}
70