Passed
Push — master ( 6a8a74...0663e6 )
by John
12:44
created

System::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package     Cronfig Sysinfo Library
4
 * @link        https://github.com/cronfig/sysinfo
5
 * @license     http://opensource.org/licenses/MIT
6
 */
7
8
namespace Cronfig\Sysinfo;
9
10
use Cronfig\Sysinfo\Linux;
11
use Cronfig\Sysinfo\Mac;
12
13
/**
14
 * Class System
15
 */
16
class System
17
{
18
    public function __construct($customs = [])
19
    {
20
        $defaults = [
21
            Linux::class,
22
            Mac::class,
23
        ];
24
25
        $osToRegister = array_merge($defaults, $customs);
26
27
        foreach ($osToRegister as $os) {
28
            $this->registerOs($os);
29
        }
30
    }
31
32
    public function registerOs(array $classNames)
33
    {
34
        foreach ($classNames as $className) {
35
            $os = new $className;
36
37
            if ($os->inUse()) {
38
                $this->os = $os;
0 ignored issues
show
Bug Best Practice introduced by
The property os does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
40
                // The OS has been found, no need to iterate anymore
41
                break;
42
            }
43
        }
44
    }
45
46
    public function getOs()
47
    {
48
        return $this->os;
49
    }
50
}
51