Completed
Push — master ( 9a9646...b519dc )
by Adam
02:06
created

Output::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace BestServedCold\Benchmark;
4
5
use BestServedCold\Benchmark\Output\Console;
6
use BestServedCold\Benchmark\Output\Html;
7
use BestServedCold\Benchmark\Output\OutputInterface;
8
9
/**
10
 * Class Output
11
 *
12
 * @package BestServedCold\Benchmark
13
 */
14
class Output
15
{
16
    /**
17
     * @var array
18
     */
19
    private static $interfaces = [
20
        Console::class => [
21
            'cli',
22
            'cli-server'
23
        ],
24
        Html::class    => [
25
            'aolserver',
26
            'apache',
27
            'apache2filter',
28
            'apache2handler',
29
            'caudium',
30
            'cgi-fcgi',
31
            'continuity',
32
            'embed',
33
            'fpm-fcgi',
34
            'isapi',
35
            'litespeed',
36
            'milter',
37
            'nsapi',
38
            'phttpd',
39
            'pi3web',
40
            'roxen',
41
            'thttpd',
42
            'tux',
43
            'webjames'
44
        ]
45
    ];
46
47
    /**
48
     * Output constructor.
49
     */
50
    public function __construct() {}
51
52
    /**
53
     * @param  Benchmark            $benchmark
54
     * @param  bool|OutputInterface $interface
55
     * @throws \Exception
56
     * @return string
57
     */
58 3
    public static function output(Benchmark $benchmark, $interface = false)
59
    {
60 3
        if (! $class = self::outputClass($interface ?: php_sapi_name())) {
61 1
            throw new \Exception('Interface ['. $interface . '] is unknown.');
62
        }
63
        
64 2
        return $class::output($benchmark);
65
    }
66
67
    /**
68
     * @param  $sapi
69
     * @return OutputInterface
70
     */
71 3
    private static function outputClass($sapi)
72
    {
73 3
        foreach (self::$interfaces as $key => $value) {
74 3
            if (in_array($sapi, $value)) {
75 2
                return $key;
76
            }
77 3
        }
78 1
    }
79
80
}
81