Completed
Push — master ( b829e8...5d217f )
by Guillaume
02:31
created

CsvRenderer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
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
8
/**
9
 * @author Guillaume Cavana <[email protected]>
10
 */
11
class CsvRenderer implements RendererInterface
12
{
13
    protected $io;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param IO $io
19
     */
20
    public function __construct(IO $io)
21
    {
22
        $this->io = $io;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function render(ResultCollection $resultCollection)
29
    {
30
        $stream = fopen('php://temp', 'w');
31
        fputcsv(
32
            $stream,
33
            [
34
                'Name',
35
                'Status',
36
                'Reponse Time',
37
            ]
38
        );
39
40
        foreach ($resultCollection as $result) {
41
            fputcsv(
42
                $stream,
43
                [
44
                    $result->getName(),
45
                    $result->getStatusCode(),
46
                    $result->getReponseTime(),
47
                ]
48
            );
49
        }
50
        rewind($stream);
51
        $this->io->write(stream_get_contents($stream));
52
        fclose($stream);
53
    }
54
}
55