Test Failed
Push — master ( 3d84ae...df3782 )
by Moecasts
04:52
created

DeviceType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 10
wmc 8
1
<?php
2
3
namespace Moecasts\Laravel\UserLoginLog;
4
5
use Jenssegers\Agent\Agent;
6
7
class DeviceType
8
{
9
    const DESKTOP = 1;
10
    const TABLET = 2;
11
    const PHONE = 3;
12
    const ROBOT = 4;
13
14 2
    public static function getType(int $value): ?String
15
    {
16 2
        $class = new \ReflectionClass(get_called_class());
17
18 2
        $constants = $class->getConstants();
19
20 2
        foreach ($constants as $name => $val) {
21 2
            if ($val === $value) {
22 2
                return $name;
23
            }
24
        }
25
26 1
        return null;
27
    }
28
29 7
    public static function getValue(Agent $agent): ?int
30
    {
31 7
        if ($agent->isTablet()) {
32 7
            return DeviceType::TABLET;
33 1
        } else if ($agent->isPhone()) {
34 1
            return DeviceType::PHONE;
35 1
        } elseif ($agent->isRobot()) {
36 1
            return DeviceType::ROBOT;
37 1
        } else {
38 1
            return DeviceType::DESKTOP
39
        }
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected '}', expecting ';' on line 39 at column 8
Loading history...
40
    }
41
}
42