Test Setup Failed
Push — master ( 48ff30...fb5a71 )
by Antonio Carlos
02:17
created

Timer::getSBInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PragmaRX\Health\Support;
4
5
use \SebastianBergmann\Timer\Timer as SBTimer;
6
7 8
class Timer
8
{
9 8
    public static function start()
10 8
    {
11 8
        return class_exists('SebastianBergmann\Timer\Timer')
12
            ? static::startSB()
13
            : \PHP_Timer::start();
14 8
    }
15
16 8
    public static function stop()
17 8
    {
18 8
        return class_exists('SebastianBergmann\Timer\Timer')
19
            ? static::stopSB()
20
            : \PHP_Timer::stop();
21
    }
22
23
    public static function startSB()
24
    {
25
        return static::isStatic() ? SBTimer::start() : static::getSBInstance()->start();
26
    }
27
28
    public static function stopSB()
29
    {
30
        return static::isStatic() ? SBTimer::start() : static::getSBInstance()->start();
31
    }
32
33
    public static function isStatic()
34
    {
35
        return static::getStaticMethodNames()->contains('start');
36
    }
37
38
    public static function getSBInstance()
39
    {
40
        return new SBTimer();
41
    }
42
43
    public static function getStaticMethodNames()
44
    {
45
        return collect((new \ReflectionClass(SBTimer::class))->getMethods(\ReflectionMethod::IS_STATIC))->map(function ($method) {
46
            return $method->name;
47
        });
48
    }
49
}
50