Completed
Pull Request — master (#14)
by Simon
02:03
created

LogFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B entryToUl() 0 24 5
1
<?php
2
3
namespace SilverLeague\LogViewer\Helper;
4
5
/**
6
 * Class LogFormatter formats the array to a readable unordered list
7
 *
8
 * @package SilverLeague\LogViewer\Helper
9
 *
10
 * @author Simon Erkelens <[email protected]>
11
 */
12
class LogFormatter
13
{
14
15
    /**
16
     * @var array for future reference
17
     */
18
    private static $icons = [
0 ignored issues
show
Unused Code introduced by
The property $icons is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'DEBUG'     => 'info-cirled',
20
        'INFO'      => 'help-circled',
21
        'NOTICE'    => 'help-plus-circled',
22
        'WARNING'   => 'info-circled',
23
        'ERROR'     => 'cancel-circled',
24
        'CRITICAL'  => 'cancel-circled',
25
        'ALERT'     => 'help-circled',
26
        'EMERGENCY' => 'cancel-circled'
27
    ];
28
29
    /**
30
     * Recursive method, will call itself if a sub element is an array
31
     * @param array $data
32
     * @param bool $first start with an opening bracket? if true, skip (counterintuitive, but naming)
33
     * @return string formatted <ul><li> of the array;
34
     */
35
    public static function entryToUl($data, $first = true)
36
    {
37
        $out = $first ? '<span style="color: #007700">[</span>' : '';
38
        $out .= '<ul style="margin-bottom: 0">';
39
        foreach ($data as $key => $arrayItem) {
40
            if (!is_array($arrayItem)) {
41
                $out .= '<li class="list-unstyled">' .
42
                    '<span style="color: #0000BB">' . $key . '</span>' .
43
                    '<span style="color: #007700">: </span>' .
44
                    '<span style="color: #DD0000">' . $arrayItem . '</span>'.
45
                    '</li>';
46
            } else {
47
                $out .= '<li class="list-unstyled">' .
48
                    '<span style="color: #0000BB">' . $key . '</span>' .
49
                    '<span style="color: #007700">: </span>' .
50
                    self::entryToUl($arrayItem) .
51
                    '</li>';
52
            }
53
        }
54
        $out .= '</ul>';
55
        $out .= $first ? '<span style="color: #007700">]</span>' : '';
56
57
        return $out;
58
    }
59
60
}