| Total Complexity | 8 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
||
| 42 |