SystemTable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 6
Bugs 1 Features 5
Metric Value
dl 0
loc 35
rs 10
c 6
b 1
f 5
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSystemIdentifier() 0 9 3
A getMap() 0 4 1
1
<?php
2
3
namespace Uptime\System;
4
5
class SystemTable
6
{
7
    /**
8
     * Map relating possible values of `PHP_OS` and widely known OS groups
9
     *
10
     * Values should be declared in lowercase.
11
     *
12
     * @link http://stackoverflow.com/questions/738823/possible-values-for-php-os
13
     * @link http://en.wikipedia.org/wiki/Uname#Table_of_standard_uname_output
14
     * @link https://github.com/php/php-src/blob/5b1f6caaf0574cd72396b1b4c671bae82557c4b4/configure.in
15
     */
16
    protected static $map = [
17
        'Linux'   => [ 'linux', 'cygwin', 'linux-armv71', 'linux2', 'unix', 'sunos'], // `cat /proc/uptime`
18
        'Darwin'  => [ 'darwin', 'mac', 'osx'], //  `sysctl kern.boottime`
19
        'BSD'     => [ 'freebsd', 'openbsd', 'netbsd', 'bsd' ], // `sysctl kern.boottime`
20
        'Windows' => [ 'win32', 'winnt', 'windows' ], // `wmic os get lastbootuptime`
21
        'OpenVMS' => [ 'openvms' ] // `show system/noprocess`
22
    ];
23
24
    public static function getSystemIdentifier($system)
25
    {
26
        $system = strtolower($system);
27
        foreach (self::getMap() as $identifier => $systems) {
28
            if( in_array($system, $systems) ) return $identifier;
29
        }
30
31
        return false;
32
    }
33
34
    public static function getMap()
35
    {
36
        return self::$map;
37
    }
38
39
}
40