1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BestServedCold\Benchmark\Output; |
4
|
|
|
|
5
|
|
|
use BestServedCold\Benchmark\Benchmark; |
6
|
|
|
use BestServedCold\HTMLBuilder\Output; |
7
|
|
|
use BestServedCold\HTMLBuilder\Html as HtmlBuilder; |
8
|
|
|
use BestServedCold\PhalueObjects\Metric; |
9
|
|
|
use BestServedCold\HTMLBuilder\Html\Node; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Html |
13
|
|
|
* |
14
|
|
|
* @package BestServedCold\Benchmark\Output |
15
|
|
|
*/ |
16
|
|
|
class Html extends AbstractOutput implements HTMLOutputInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param Benchmark $benchmark |
20
|
|
|
* @return $this |
21
|
|
|
*/ |
22
|
2 |
|
public static function output(Benchmark $benchmark) |
23
|
|
|
{ |
24
|
2 |
|
return new static((new Output( |
25
|
2 |
|
HtmlBuilder::table(self::tHead(), self::tBody($benchmark))) |
26
|
2 |
|
)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return Node |
31
|
|
|
*/ |
32
|
2 |
|
private static function tHead() |
33
|
|
|
{ |
34
|
2 |
|
return HtmlBuilder::thead(HtmlBuilder::tr(self::tHeadMap())); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
2 |
|
private static function tHeadMap() |
41
|
|
|
{ |
42
|
|
|
return array_map(function($header) { |
43
|
2 |
|
return HtmlBuilder::th()->content($header); }, self::$headers |
44
|
2 |
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Benchmark $benchmark |
49
|
|
|
* @return Node |
50
|
|
|
*/ |
51
|
2 |
|
private static function tBody(Benchmark $benchmark) |
52
|
|
|
{ |
53
|
2 |
|
return HtmlBuilder::tbody(self::tBodyMap($benchmark) |
54
|
2 |
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param Benchmark $benchmark |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
private static function tBodyMap(Benchmark $benchmark) |
62
|
|
|
{ |
63
|
|
|
return array_map(function($name, $value) { |
64
|
2 |
|
return array_map(function($metric) use ($name) { |
65
|
2 |
|
return self::tBodyRow($metric, $name); |
66
|
2 |
|
}, $value); |
67
|
2 |
|
}, array_keys($benchmark->getMarkers()), $benchmark->getMarkers()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param Metric $metric |
72
|
|
|
* @param string $name |
73
|
|
|
* @return Node |
74
|
|
|
*/ |
75
|
2 |
|
private static function tBodyRow(Metric $metric, $name) |
76
|
|
|
{ |
77
|
2 |
|
return HtmlBuilder::tr( |
78
|
2 |
|
HtmlBuilder::td()->content($name), |
79
|
2 |
|
HtmlBuilder::td()->content($metric->getShortName()), |
80
|
2 |
|
HtmlBuilder::td()->content(static::metricOutput($metric)) |
81
|
2 |
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|