1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BestServedCold\Benchmark\Output; |
4
|
|
|
|
5
|
|
|
use BestServedCold\Benchmark\Benchmark, |
6
|
|
|
BestServedCold\HTMLBuilder\Output, |
7
|
|
|
BestServedCold\HTMLBuilder\Html as HtmlBuilder, |
8
|
|
|
BestServedCold\PhalueObjects\Metric, |
9
|
|
|
BestServedCold\HTMLBuilder\Html\Node; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Html |
13
|
|
|
* |
14
|
|
|
* @package BestServedCold\Benchmark\Output |
15
|
|
|
*/ |
16
|
|
|
class Html extends AbstractOutput implements OutputInterface |
17
|
|
|
{ |
18
|
1 |
|
public function render() |
19
|
|
|
{ |
20
|
1 |
|
echo $this->output->get(); |
21
|
1 |
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Benchmark $benchmark |
25
|
|
|
* @return $this |
26
|
|
|
*/ |
27
|
2 |
|
public static function output(Benchmark $benchmark) |
28
|
|
|
{ |
29
|
2 |
|
return new static((new Output( |
30
|
2 |
|
HtmlBuilder::table(self::tHead(),self::tBody($benchmark))) |
|
|
|
|
31
|
2 |
|
)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return Node |
36
|
|
|
*/ |
37
|
2 |
|
private static function tHead() |
38
|
|
|
{ |
39
|
2 |
|
return HtmlBuilder::thead(HtmlBuilder::tr(self::tHeadMap())); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
2 |
|
private static function tHeadMap() |
46
|
|
|
{ |
47
|
|
|
return array_map(function($header) { |
48
|
2 |
|
return HtmlBuilder::th()->content($header); }, self::$headers |
|
|
|
|
49
|
2 |
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Benchmark $benchmark |
54
|
|
|
* @return Node |
55
|
|
|
*/ |
56
|
2 |
|
private static function tBody(Benchmark $benchmark) |
57
|
|
|
{ |
58
|
2 |
|
return HtmlBuilder::tbody(self::tBodyMap($benchmark) |
59
|
2 |
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param Benchmark $benchmark |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
private static function tBodyMap(Benchmark $benchmark) |
67
|
|
|
{ |
68
|
|
|
return array_map(function($name, $value) { |
69
|
2 |
|
return array_map(function($metric) use ($name) { |
70
|
2 |
|
return self::tBodyRow($metric, $name); |
71
|
2 |
|
}, $value); |
72
|
2 |
|
}, array_keys($benchmark->getMarkers()), $benchmark->getMarkers()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param Metric $metric |
77
|
|
|
* @param string $name |
78
|
|
|
* @return Node |
79
|
|
|
*/ |
80
|
2 |
|
private static function tBodyRow(Metric $metric, $name) |
81
|
|
|
{ |
82
|
2 |
|
return HtmlBuilder::tr( |
83
|
2 |
|
HtmlBuilder::td()->content($name), |
|
|
|
|
84
|
2 |
|
HtmlBuilder::td()->content($metric->getShortName()), |
|
|
|
|
85
|
2 |
|
HtmlBuilder::td()->content(static::metricOutput($metric)) |
|
|
|
|
86
|
2 |
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.