Passed
Push — master ( 5fda7a...160783 )
by George
03:22
created

Error::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace JsonTable\Analyse;
3
4
/**
5
 * Details of errors found during an analysis.
6
 *
7
 * @package    JSON table
8
 */
9
class Error
10
{
11
    /**
12
     * @static
13
     *
14
     * @var array   Error messages.
15
     */
16
    private static $errors = [];
17
18
19
    /**
20
     * Reset the errors.
21
     */
22 81
    public static function reset()
23
    {
24 81
        self::$errors = [];
25 81
    }
26
27
28
    /**
29
     * Get all errors that have been set during the analysis.
30
     *
31
     * @return  array   The error messages.
32
     */
33 76
    public function getErrors()
34
    {
35 76
        $errorsFormatted = [];
36
37
        // Format the error type with the number of errors of that type.
38 76
        foreach (self::$errors as $errorType => $errors) {
39 50
            $errorTypeFormatted = sprintf($errorType, count($errors));
40 50
            $errorsFormatted[$errorTypeFormatted] = $errors;
41 76
        }
42
43 76
        return $errorsFormatted;
44
    }
45
46
47
    /**
48
     * Add an error message.
49
     *
50
     * @param   string  $type   The type of error.
51
     * @param   string  $error  The error message (or field).
52
     *
53
     * @return  void
54
     */
55 50
    public function setError($type, $error)
56
    {
57 50
        if (!array_key_exists($type, self::$errors)) {
58 50
            self::$errors[$type] = [];
59 50
        }
60
61 50
        array_push(self::$errors[$type], $error);
62
    }
63
}