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

bin/Register.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Install functions
5
 *
6
 * Used through vendor/bin/phpcompat_(en|dis)able
7
 *
8
 */
9
10
class PHPCompatibility_Register {
11
	
12
    static function update() {
0 ignored issues
show
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...
13
        self::register_in_cs();
14
    }
15
16
    static function register_in_cs() {
17
        $installed_paths = self::get_installed_path();
18
        $target_path     = dirname(__DIR__);
19
        if (in_array($target_path, $installed_paths, true)) {
20
            echo "Our path is already registered in PHP CodeSniffer\n";
21
        } else {
22
            array_push($installed_paths, $target_path);
23
            self::set_installed_path($installed_paths);
24
            echo "Registered our path in PHP CodeSniffer\n";
25
        }
26
    }
27
28
    static function get_installed_path() {
29
        $installed_paths = PHP_CodeSniffer::getConfigData('installed_paths');
30
        if ( $installed_paths === null || strlen($installed_paths) === 0 ) {
31
            // Because: explode(',' , NULL) == array('')
32
            // and we assert no data is empty array
33
            return array();
34
        }
35
        return explode(',', $installed_paths);
36
    }
37
38
    static function set_installed_path($array) {
39
        if(count($array) === 0) {
40
            PHP_CodeSniffer::setConfigData('installed_paths', null);
41
        } else {
42
            PHP_CodeSniffer::setConfigData('installed_paths', implode(',', $array));
43
        }
44
    }
45
}
46