Completed
Push — master ( 98aac0...15b539 )
by Hannes
02:24
created

ErrorObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 41
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hasErrors() 4 4 1
A getErrors() 4 4 1
A addError() 4 4 1
A resetErrors() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
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