Completed
Branch TEMP/gza_copy_hack (130071)
by Juliette
06:28
created

PHPCompatibility_Install::set_installed_path()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/**
4
 * Install functions
5
 *
6
 * Used through vendor/bin/phpcompat_(en|dis)able
7
 *
8
 */
9
10
class PHPCompatibility_Install {
11
	
12
	/**
13
	 * Files which need to be copied over and live in the root directory of this project.
14
	 *
15
	 * @var array
16
	 */
17
    public static $root_dir_files = array(
18
        'ruleset.xml',
19
        'Sniff.php',
20
    );
21
22
    static function enable() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
        echo "(Re-)Enabling PHPCompatibility\n";
24
        self::make_copy();
25
    }
26
27
    static function disable() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
        self::remove_copy();
29
    }
30
31
    static function update() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
        self::disable();
33
        self::enable();
34
    }
35
36
    static function make_copy() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
        $srcDir = dirname(__DIR__);
38
        $copy = dirname(__DIR__).DIRECTORY_SEPARATOR.'PHPCompatibility';
39
40
        if ( file_exists ($copy)) {
41
            echo "Copy workaround is already in place\n";
42
            return;
43
        }
44
45
        if (mkdir($copy) === true) {
46
            foreach (self::$root_dir_files as $filename) {
47
                copy($srcDir.DIRECTORY_SEPARATOR.$filename, $copy.DIRECTORY_SEPARATOR.$filename);
48
            }
49
50
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
51
                $copy = str_replace('/', DIRECTORY_SEPARATOR, $copy);
52
                $srcDir = str_replace('/', DIRECTORY_SEPARATOR, $srcDir);
53
                passthru('xcopy "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs" /S /E /I');
54
            } else {
55
                passthru('cp -r "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs"');
56
            }
57
            echo "Created copy workaround\n";
58
        } else {
59
            echo "Failed to create the $copy directory\n";
60
        }
61
    }
62
63
    static function remove_copy() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
        $copy = dirname(__DIR__).DIRECTORY_SEPARATOR.'PHPCompatibility';
65
66
        if ( ! file_exists ($copy)) {
67
            echo "No copy workaround to remove\n";
68
            return;
69
        }
70
71
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
72
            $copy = str_replace('/', DIRECTORY_SEPARATOR, $copy);
73
            passthru('rmdir /S /Q "'.$copy.'"');
74
        } else {
75
            passthru('rm -rf "'.$copy.'"');
76
        }
77
        echo "Copy workaround removed\n";
78
    }
79
80
}
81