SystemFactory::getSystem()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.0625
1
<?php
2
3
namespace League\CLImate\Util\System;
4
5
class SystemFactory
6
{
7
    /**
8
     * @var \League\CLImate\Util\System\System $instance
9
     */
10
11
    protected static $instance;
12
13
    /**
14
     * Get an instance of the appropriate System class
15
     *
16
     * @return \League\CLImate\Util\System\System
17
     */
18
19 948
    public static function getInstance()
20
    {
21 948
        if (static::$instance) {
22 944
            return static::$instance;
23
        }
24
25 4
        static::$instance = self::getSystem();
26
27 4
        return static::$instance;
28
    }
29
30
    /**
31
     * Set the $instance property to the appropriate system
32
     *
33
     * @return \League\CLImate\Util\System\System
34
     */
35
36 4
    protected static function getSystem()
37
    {
38 4
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
39
            return new Windows();
40
        }
41
42 4
        return new Linux();
43
    }
44
}
45