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

PHPCompatibility_Register::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
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...
13
        self::register_in_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
        $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() {
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...
29
        $installed_paths = PHP_CodeSniffer::getConfigData('installed_paths');
30
        if ( $installed_paths === null || strlen($installed_paths) === 0 ) {
31
            // Because: explode(',' , NULL) == array('')
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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) {
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...
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