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

Error   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 55
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reset() 0 4 1
A getErrors() 0 12 2
A setError() 0 8 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
     * 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
}