Passed
Push — code-style-bis ( 9e1124...1907a1 )
by Arnaud
10:45 queued 07:51
created

Plateform::getOS()   B

Complexity

Conditions 11
Paths 11

Size

Total Lines 21
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
eloc 19
c 2
b 0
f 0
nc 11
nop 0
dl 0
loc 21
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Util;
12
13
class Plateform
14
{
15
    const OS_UNKNOWN = 1;
16
    const OS_WIN = 2;
17
    const OS_LINUX = 3;
18
    const OS_OSX = 4;
19
20
    protected static $pharPath;
21
22
    /**
23
     * Running from Phar or not?
24
     *
25
     * @return bool
26
     */
27
    public static function isPhar(): bool
28
    {
29
        if (!empty(\Phar::running())) {
30
            self::$pharPath = \Phar::running();
31
32
            return true;
33
        }
34
35
        return false;
36
    }
37
38
    /**
39
     * Returns the full path on disk to the currently executing Phar archive.
40
     *
41
     * @return string
42
     */
43
    public static function getPharPath(): string
44
    {
45
        if (!isset(self::$pharPath)) {
46
            self::isPhar();
47
        }
48
49
        return self::$pharPath;
50
    }
51
52
    /**
53
     * Whether the host machine is running a Windows OS.
54
     *
55
     * @return bool
56
     */
57
    public static function isWindows(): bool
58
    {
59
        return defined('PHP_WINDOWS_VERSION_BUILD');
60
    }
61
62
    /**
63
     * Opens a URL in the system default browser.
64
     *
65
     * @param string $url
66
     *
67
     * @return void
68
     */
69
    public static function openBrowser($url): void
70
    {
71
        if (self::isWindows()) {
72
            passthru('start "web" explorer "'.$url.'"');
73
        } else {
74
            passthru('which xdg-open', $linux);
75
            passthru('which open', $osx);
76
            if (0 === $linux) {
77
                passthru('xdg-open '.$url);
78
            } elseif (0 === $osx) {
79
                passthru('open '.$url);
80
            }
81
        }
82
    }
83
84
    /**
85
     * Search for system OS in PHP_OS constant.
86
     *
87
     * @return int
88
     */
89
    public static function getOS(): int
90
    {
91
        switch (PHP_OS) {
92
            case 'Unix':
93
            case 'FreeBSD':
94
            case 'NetBSD':
95
            case 'OpenBSD':
96
            case 'Linux':
97
                return self::OS_LINUX;
98
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
99
            case 'WINNT':
100
            case 'WIN32':
101
            case 'Windows':
102
            case 'CYGWIN_NT':
103
                return self::OS_WIN;
104
                break;
105
            case 'Darwin':
106
                return self::OS_OSX;
107
                break;
108
            default:
109
                return self::OS_UNKNOWN;
110
        }
111
    }
112
}
113