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