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
|
|
|
|