Completed
Push — master ( 11b1e9...e2c620 )
by Adam
02:05
created

Html::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
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
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)))
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...
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
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...
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),
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...
79 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...
80 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...
81 2
         );
82
    }
83
}
84