Completed
Pull Request — master (#235)
by
unknown
03:14
created

PHPCompatibility_Install   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 1
dl 0
loc 74
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A enable() 0 5 1
A disable() 0 5 1
A register_in_cs() 0 10 3
A unregister_from_cs() 0 8 2
A make_copy() 0 22 3
A remove_copy() 0 16 3
1
<?php 
2
3
class PHPCompatibility_Install {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
    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...
5
        echo "Enabling PHPCompatibility\n";
6
        self::make_copy();
7
        self::register_in_cs();
8
    }
9
    
10
    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...
11
        echo "Disabling PHPCompatibility\n";
12
        self::remove_copy();
13
        self::unregister_from_cs();
14
    }
15
    
16
    static function register_in_cs() {
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...
17
        if (PHP_CodeSniffer::getConfigData('installed_paths') === NULL) {
18
            PHP_CodeSniffer::setConfigData('installed_paths', __DIR__);
19
            echo "Registered our path in PHP CodeSniffer\n";
20
        } else if (PHP_CodeSniffer::getConfigData('installed_paths') === __DIR__ ) {
21
            echo "Our path is already registered in PHP CodeSniffer\n";;
22
        } else {
23
            throw new Exception("Another path is registered in Code Sniffer conf :(");
24
        }
25
    }
26
    
27
    static function unregister_from_cs() {
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
        if (PHP_CodeSniffer::getConfigData('installed_paths') === __DIR__) {
29
            PHP_CodeSniffer::setConfigData('installed_paths', NULL);
30
            echo "Unregistered our path in PHP CodeSniffer\n";
31
        } else {
32
            echo "No path registered in Code Sniffer\n";
33
        }
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 = __DIR__;
38
        $copy = __DIR__ .DIRECTORY_SEPARATOR.'PHPCompatibility';
39
        
40
        if ( file_exists ($copy)) {
41
            echo "Copy hack is already in place\n";
42
            return;
43
        }
44
        
45
        mkdir($copy);
46
        copy(__DIR__ .DIRECTORY_SEPARATOR.'ruleset.xml', $copy.DIRECTORY_SEPARATOR.'ruleset.xml');
47
        copy(__DIR__ .DIRECTORY_SEPARATOR.'Sniff.php', $copy.DIRECTORY_SEPARATOR.'Sniff.php');
48
        
49
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
50
            $copy = str_replace('/', DIRECTORY_SEPARATOR, $copy);
51
            $srcDir = str_replace('/', DIRECTORY_SEPARATOR, $srcDir);
52
            passthru('xcopy "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs" /S /E /I');
53
        } else {
54
            passthru('cp -r "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs"');
55
        }
56
        echo "Created copy hack\n";
57
    }    
58
    
59
    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...
60
        $copy = __DIR__ .DIRECTORY_SEPARATOR.'PHPCompatibility';
61
        
62
        if ( ! file_exists ($copy)) {
63
            echo "No copy hack to remove\n";
64
            return;
65
        }
66
        
67
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
68
            $copy = str_replace('/', DIRECTORY_SEPARATOR, $copy);
69
            passthru('rmdir /S /Q "'.$copy.'"');
70
        } else {
71
            passthru('rm -rf "'.$copy.'"');
72
        }
73
        echo "Copy hack removed\n";
74
    }
75
    
76
}
77