Completed
Push — cecil ( 66a45a )
by Arnaud
02:09
created

Plateform::isPhar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/*
3
 * This file is part of the PHPoole/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
    protected static $pharPath;
16
17
    /**
18
     * Running from Phar or not?
19
     *
20
     * @return bool
21
     */
22
    public static function isPhar()
23
    {
24
        if (!empty(\Phar::running())) {
25
            self::$pharPath = \Phar::running();
26
27
            return true;
28
        }
29
30
        return false;
31
    }
32
33
    /**
34
     * Returns the full path on disk to the currently executing Phar archive.
35
     */
36
    public static function getPharPath()
37
    {
38
        if (!isset(self::$pharPath)) {
39
            self::isPhar();
40
        }
41
42
        return self::$pharPath;
43
    }
44
45
    /**
46
     * @return bool Whether the host machine is running a Windows OS
47
     */
48
    public static function isWindows()
49
    {
50
        return defined('PHP_WINDOWS_VERSION_BUILD');
51
    }
52
53
    /**
54
     * Opens a URL in the system default browser.
55
     *
56
     * @param string $url
57
     */
58
    public static function openBrowser($url)
59
    {
60
        if (self::isWindows()) {
61
            passthru('start "web" explorer "'.$url.'"');
62
        } else {
63
            passthru('which xdg-open', $linux);
64
            passthru('which open', $osx);
65
            if (0 === $linux) {
66
                passthru('xdg-open '.$url);
67
            } elseif (0 === $osx) {
68
                passthru('open '.$url);
69
            }
70
        }
71
    }
72
}
73