Completed
Push — master ( 5d5235...483143 )
by Guillaume
04:19
created

TableRenderer::render()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 8.9197
cc 4
eloc 15
nc 3
nop 1
1
<?php
2
3
namespace Hogosha\Monitor\Renderer;
4
5
use Hogosha\Monitor\Model\ResultCollection;
6
use Webmozart\Console\Api\IO\IO;
7
use Webmozart\Console\UI\Component\Table;
8
9
/**
10
 * @author Guillaume Cavana <[email protected]>
11
 */
12
class TableRenderer implements RendererInterface
13
{
14
    protected $io;
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param IO $io
20
     */
21
    public function __construct(IO $io)
22
    {
23
        $this->io = $io;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function render(ResultCollection $resultCollection)
30
    {
31
        $table = new Table();
32
        $table
33
            ->setHeaderRow(['Global Status', 'Status Code', 'Name', 'Response Time']);
34
35
        foreach ($resultCollection as $result) {
36
            $color = $result->getExpectedStatus() != $result->getStatusCode() ? 'red' : 'green';
37
            $table->addRow([
38
                $result->getExpectedStatus() != $result->getStatusCode() ? 'FAIL' : 'OK',
39
                sprintf(
40
                    '<bg=%s>%s</>',
41
                    $color,
42
                    $result->getStatusCode()
43
                ),
44
                $result->getName(),
45
                $result->getReponseTime(),
46
            ]);
47
        }
48
49
        $table->render($this->io);
50
    }
51
}
52