HtmlFormatter::writeArray()   B
last analyzed

Complexity

Conditions 6
Paths 11

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 38
rs 8.439
cc 6
eloc 23
nc 11
nop 1
1
<?php
2
/**
3
 * Scabbia2 Formatters Component
4
 * https://github.com/eserozvataf/scabbia2
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @link        https://github.com/eserozvataf/scabbia2-formatters for the canonical source repository
10
 * @copyright   2010-2016 Eser Ozvataf. (http://eser.ozvataf.com/)
11
 * @license     http://www.apache.org/licenses/LICENSE-2.0 - Apache License, Version 2.0
12
 */
13
14
namespace Scabbia\Formatters;
15
16
use Scabbia\Formatters\FormatterInterface;
17
18
/**
19
 * Implementation for generation of output in Html format
20
 *
21
 * @package     Scabbia\Formatters
22
 * @author      Eser Ozvataf <[email protected]>
23
 * @since       2.0.0
24
 */
25
class HtmlFormatter implements FormatterInterface
26
{
27
    /**
28
     * Writes given message in header format
29
     *
30
     * @param int    $uHeading size
31
     * @param string $uMessage message
32
     *
33
     * @return void
34
     */
35
    public function writeHeader($uHeading, $uMessage)
36
    {
37
        echo "<h{$uHeading}>{$uMessage}</h{$uHeading}>";
38
    }
39
40
    /**
41
     * Writes given message in specified color
42
     *
43
     * @param string $uColor   color
44
     * @param string $uMessage message
45
     *
46
     * @return void
47
     */
48
    public function writeColor($uColor, $uMessage)
49
    {
50
        echo "<div style=\"color: {$uColor};\">{$uMessage}</div>";
51
    }
52
53
    /**
54
     * Writes given message
55
     *
56
     * @param string $uMessage message
57
     *
58
     * @return void
59
     */
60
    public function write($uMessage)
61
    {
62
        echo "<div>{$uMessage}</div>";
63
    }
64
65
    /**
66
     * Outputs the array in HTML representation
67
     *
68
     * @param array $uArray Target array will be printed
69
     *
70
     * @return void
71
     */
72
    public function writeArray(array $uArray)
73
    {
74
        /** @type string $tEntryKey */
75
        /** @type array $tEntry */
76
        foreach ($uArray as $tEntryKey => $tEntry) {
77
            echo "<p>";
78
            echo "<strong>{$tEntryKey}:</strong><br />";
79
            echo "<ul>";
80
81
            $tPassed = true;
82
            /** @type array $tTest */
83
            foreach ($tEntry as $tTest) {
84
                if ($tTest["failed"]) {
85
                    $tPassed = false;
86
                    $tColor = "red";
87
                } else {
88
                    $tColor = "green";
89
                }
90
91
                echo "<li>";
92
                echo "<span style=\"color: {$tColor};\">{$tTest["operation"]}</span>";
93
                if ($tTest["message"] !== null) {
94
                    echo ": {$tTest["message"]}";
95
                }
96
                echo "</li>";
97
            }
98
99
            echo "</ul>";
100
101
            if (!$tPassed) {
102
                echo "<span style=\"color: red;\">FAILED</span>";
103
            } else {
104
                echo "<span style=\"color: green;\">PASSED</span>";
105
            }
106
107
            echo "</p>";
108
        }
109
    }
110
}
111