Completed
Push — open-in-editor ( 699198 )
by Arnaud
02:43
created

Plateform::getOS()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 0
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
0 ignored issues
show
Coding Style introduced by
Plateform does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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()
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
    public static function getPharPath()
42
    {
43
        if (!isset(self::$pharPath)) {
44
            self::isPhar();
45
        }
46
47
        return self::$pharPath;
48
    }
49
50
    /**
51
     * @return bool Whether the host machine is running a Windows OS
52
     */
53
    public static function isWindows()
54
    {
55
        return defined('PHP_WINDOWS_VERSION_BUILD');
56
    }
57
58
    /**
59
     * Opens a URL in the system default browser.
60
     *
61
     * @param string $url
62
     */
63
    public static function openBrowser($url)
64
    {
65
        if (self::isWindows()) {
66
            passthru('start "web" explorer "'.$url.'"');
67
        } else {
68
            passthru('which xdg-open', $linux);
69
            passthru('which open', $osx);
70
            if (0 === $linux) {
71
                passthru('xdg-open '.$url);
72
            } elseif (0 === $osx) {
73
                passthru('open '.$url);
74
            }
75
        }
76
    }
77
78
    /**
79
     * @return int
80
     */
81
    static public function getOS() {
82
        switch (true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing stristr(PHP_OS, 'DAR') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing stristr(PHP_OS, 'WIN') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
Bug Best Practice introduced by
It seems like you are loosely comparing stristr(PHP_OS, 'LINUX') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
83
            case stristr(PHP_OS, 'DAR'): return self::OS_OSX;
84
            case stristr(PHP_OS, 'WIN'): return self::OS_WIN;
85
            case stristr(PHP_OS, 'LINUX'): return self::OS_LINUX;
86
            default : return self::OS_UNKNOWN;
87
        }
88
    }
89
}
90