Completed
Push — master ( 997958...c1a544 )
by Adam
02:44
created

Html::tHead()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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)))
1 ignored issue
show
Unused Code introduced by
The call to Html::table() has too many arguments starting with self::tBody($benchmark).

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.

Loading history...
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
1 ignored issue
show
Bug introduced by
The call to th() misses a required argument $...$arguments.

This check looks for function calls that miss required arguments.

Loading history...
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),
1 ignored issue
show
Bug introduced by
The call to td() misses a required argument $...$arguments.

This check looks for function calls that miss required arguments.

Loading history...
84 2
             HtmlBuilder::td()->content($metric->getShortName()),
2 ignored issues
show
Bug introduced by
The call to td() misses a required argument $...$arguments.

This check looks for function calls that miss required arguments.

Loading history...
Unused Code introduced by
The call to Html::tr() has too many arguments starting with \BestServedCold\HTMLBuil...metric->getShortName()).

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.

Loading history...
85 2
             HtmlBuilder::td()->content(static::metricOutput($metric))
1 ignored issue
show
Bug introduced by
The call to td() misses a required argument $...$arguments.

This check looks for function calls that miss required arguments.

Loading history...
86 2
         );
87
    }
88
}
89