AbstractOutput   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 1
dl 0
loc 58
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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