Passed
Push — master ( 0cd8c1...21e99f )
by George
03:10
created

Error::getErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 2
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
     * Get all errors that have been set during the analysis.
21
     *
22
     * @return  array   The error messages.
23
     */
24 31
    public function getErrors()
25
    {
26 31
        $errorsFormatted = [];
27
28
        // Format the error type with the number of errors of that type.
29 31
        foreach (self::$errors as $errorType => $errors) {
30 11
            $errorTypeFormatted = sprintf($errorType, count($errors));
31 11
            $errorsFormatted[$errorTypeFormatted] = $errors;
32 31
        }
33
34 31
        return $errorsFormatted;
35
    }
36
37
38
    /**
39
     * Add an error message.
40
     *
41
     * @param   string  $type   The type of error.
42
     * @param   string  $error  The error message (or field).
43
     *
44
     * @return  void
45
     */
46 11
    public function setError($type, $error)
47
    {
48 11
        if (!array_key_exists($type, self::$errors)) {
49 11
            self::$errors[$type] = [];
50 11
        }
51
52 11
        array_push(self::$errors[$type], $error);
53
    }
54
}