Console   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 55
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 4 1
A output() 0 9 3
A loopRows() 0 7 3
A addRow() 0 9 2
1
<?php
2
3
namespace BestServedCold\Benchmark\Output;
4
5
use BestServedCold\Benchmark\Benchmark;
6
use BestServedCold\Benchmark\Dependency;
7
use BestServedCold\PhalueObjects\Metric;
8
use Symfony\Component\Console\Helper\Table;
9
use Symfony\Component\Console\Helper\TableSeparator;
10
11
/**
12
 * Class Console
13
 *
14
 * @package BestServedCold\Benchmark\Output
15
 */
16
class Console extends AbstractOutput implements HTMLOutputInterface
17
{
18
    /**
19
     * @codeCoverageIgnore impossible to test as writes to php://stdout
20
     */
21
    public function render()
22
    {
23
        parent::render();
24
    }
25
    
26
    /**
27
     * @param  Benchmark      $benchmark
28
     * @param  Table          $table
29
     * @param  TableSeparator $tableSeparator
30
     * @return Console
31
     */
32 1
    public static function output(Benchmark $benchmark, Table $table = null, TableSeparator $tableSeparator = null)
33
    {
34 1
        $table          = $table          ?: Dependency::symfonyTable();
35 1
        $tableSeparator = $tableSeparator ?: Dependency::symfonyTableSeparator();
36 1
        $table->setHeaders(self::$headers);
37 1
        self::loopRows($table, $tableSeparator, $benchmark->getMarkers());
38 1
        return new static($table);
39
40
    }
41
42
    /**
43
     * @param Table          $table
44
     * @param TableSeparator $tableSeparator
45
     * @param array          $rows
46
     */
47 1
    protected static function loopRows(Table $table, TableSeparator $tableSeparator, array $rows)
48
    {
49 1
        foreach($rows as $name => $row) {
50 1
            $table = static::addRow($table, $row, $name);
51 1
            $row === end($rows) ?: $table->addRow($tableSeparator);
52 1
        }
53 1
    }
54
55
    /**
56
     * @param  Table       $table
57
     * @param  array       $metrics
58
     * @param  null|string $name
59
     * @return Table
60
     */
61 1
    protected static function addRow(Table $table, array $metrics, $name = null)
62
    {
63
        /** @var Metric $metric */
64 1
        foreach ($metrics as $metric) {
65 1
            $table->addRow(static::populateRow($metric, $name));
66 1
        }
67
68 1
        return $table;
69
    }
70
}
71