ListRenderer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 0 Features 2
Metric Value
dl 0
loc 43
rs 10
c 5
b 0
f 2
wmc 6
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B render() 0 25 5
1
<?php
2
3
/*
4
 * This file is part of the hogosha-monitor package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Hogosha\Monitor\Renderer;
17
18
use Hogosha\Monitor\Guesser\StatusGuesser;
19
use Hogosha\Monitor\Model\ResultCollection;
20
use Webmozart\Console\Api\IO\IO;
21
22
/**
23
 * @author Guillaume Cavana <[email protected]>
24
 */
25
class ListRenderer implements RendererInterface
26
{
27
    protected $io;
28
29
    /**
30
     * Constructor.
31
     *
32
     * @param IO $io
33
     */
34
    public function __construct(IO $io)
35
    {
36
        $this->io = $io;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function render(ResultCollection $resultCollection)
43
    {
44
        $format = '[%s][%s] %s - %s%s%s';
45
46
        $errorFormat = ' - <bg=red>%s</>';
47
48
        $statusGuesser = new StatusGuesser();
49
50
        foreach ($resultCollection as $result) {
51
            $errorLog = $result->getHandlerError();
52
            $validatorErrorLog = $result->getValidatorError();
53
54
            $this->io->write(
55
                sprintf(
56
                    $format,
57
                    $statusGuesser->isFailed($result) ? 'FAIL' : 'OK',
58
                    $result->getStatusCode(),
59
                    $result->getUrl()->getName(),
60
                    $result->getReponseTime(),
61
                    (null !== $errorLog) ? sprintf($errorFormat, $errorLog) : '',
62
                    (null !== $validatorErrorLog) ? sprintf($errorFormat, $validatorErrorLog) : ''
63
                )."\n"
64
            );
65
        }
66
    }
67
}
68