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 OutputInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @codeCoverageIgnore impossible to test as writes to php://stdout |
20
|
|
|
*/ |
21
|
|
|
public function render() |
22
|
|
|
{ |
23
|
|
|
$this->output->render(); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param Benchmark $benchmark |
28
|
|
|
* @param Table $table |
29
|
|
|
* @param TableSeparator $tableSeparator |
30
|
|
|
* @return string |
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
|
|
|
* @param Table $table |
43
|
|
|
* @param TableSeparator $tableSeparator |
44
|
|
|
* @param array $rows |
45
|
|
|
*/ |
46
|
1 |
|
protected static function loopRows(Table $table, TableSeparator $tableSeparator, array $rows) |
47
|
|
|
{ |
48
|
1 |
|
foreach($rows as $name => $row) { |
49
|
1 |
|
$table = static::addRow($table, $row, $name); |
50
|
1 |
|
$row === end($rows) ?: $table->addRow($tableSeparator); |
51
|
1 |
|
} |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param Table $table |
56
|
|
|
* @param array $metrics |
57
|
|
|
* @param bool|string $name |
58
|
|
|
* @return Table |
59
|
|
|
*/ |
60
|
1 |
|
protected static function addRow(Table $table, array $metrics, $name) |
61
|
|
|
{ |
62
|
|
|
/** @var Metric $metric */ |
63
|
1 |
|
foreach ($metrics as $metric) { |
64
|
1 |
|
$table->addRow(parent::populateRow($metric, $name)); |
|
|
|
|
65
|
1 |
|
} |
66
|
|
|
|
67
|
1 |
|
return $table; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: