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

AbstractOutput::render()   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\HTMLBuilder\Output,
6
    BestServedCold\PhalueObjects\Metric,
7
    BestServedCold\PhalueObjects\Metric\DeclaredInterface,
8
    BestServedCold\PhalueObjects\Metric\DeclaredTrait,
9
    BestServedCold\PhalueObjects\Metric\IncludedFile,
10
    BestServedCold\PhalueObjects\Metric\DeclaredClass,
11
    BestServedCold\PhalueObjects\Metric\DefinedConstant,
12
    BestServedCold\PhalueObjects\Metric\DefinedFunction,
13
    Symfony\Component\Console\Output\OutputInterface as SymfonyOutputInterface;
14
use Symfony\Component\Console\Helper\Table;
15
16
/**
17
 * Class AbstractOutput
18
 *
19
 * @package BestServedCold\Benchmark\Output
20
 */
21
abstract class AbstractOutput
22
{
23
    /**
24
     * @var array
25
     */
26
    protected static $countMetrics = [
27
        DeclaredInterface::class,
28
        DeclaredTrait::class,
29
        IncludedFile::class,
30
        DefinedFunction::class,
31
        DeclaredClass::class,
32
        DefinedConstant::class
33
    ];
34
35
    /**
36
     * @var array
37
     */
38
    protected static $headers = ['Name', 'Metric', 'Value'];
39
40
    /**
41
     * @var Output|Table
42
     */
43
    protected $output;
44
45
    /**
46
     * AbstractOutput constructor.
47
     *
48
     * @param $output
49
     */
50 2
    public function __construct($output)
51
    {
52 2
        $this->output = $output;
53 2
    }
54
55 1
    public function render()
56
    {
57 1
        return $this->output->render();
58
    }
59
    
60
    /**
61
     * @param  Metric     $metric
62
     * @return int|string
63
     */
64 2
    protected static function metricOutput(Metric $metric)
65
    {
66 2
        return in_array(get_class($metric), self::$countMetrics) ? $metric->count() : (string) $metric;
67
    }
68
69
    /**
70
     * @param  Metric $metric
71
     * @param  string $name
72
     * @return array
73
     */
74 1
    protected static function populateRow(Metric $metric, $name)
75
    {
76 1
        return [$name, $metric->getShortName(), static::metricOutput($metric)];
77
    }
78
}
79