Completed
Push — master ( 0765b0...b884d5 )
by Anton
9s
created

update.php ➔ copyVendor()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 4
eloc 16
c 2
b 1
f 0
nc 4
nop 2
dl 0
loc 22
rs 8.9197
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Post Update Composer script
4
 *
5
 * @author Anton Shevchuk
6
 */
7
8
// Root path, one level up
9
$root = dirname(__DIR__);
10
11
12
function copyVendor($mask, $target) {
13
    global $root;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
14
15
    foreach (glob($root .'/vendor/'. $mask) as $file) {
16
        $script = pathinfo($file, PATHINFO_FILENAME);
17
        $ext = pathinfo($file, PATHINFO_EXTENSION);
18
19
        if (is_dir($file)) {
20
            $newMask = substr($mask, 0, -2) .'/'. $script .'/*';
21
            $newDir = $root .'/public/'. $target .'/'. $script;
22
            if (!is_dir($newDir)) {
23
                echo 'Make directory '. $target .'/'. $script .PHP_EOL;
24
                mkdir($root .'/public/'. $target .'/'. $script);
25
            }
26
            copyVendor($newMask, $target .'/'.$script);
27
        } else {
28
            $newFile = $root .'/public/'. $target .'/'. $script .'.'. $ext;
29
            echo '  '. $file .' >> '. $newFile .PHP_EOL;
30
            copy($file, $newFile);
31
        }
32
    }
33
}
34
35
// Copy Swagger-UI to public
36
copyVendor('public/swagger-ui/dist/*', 'api');
37
38
// Copy JavaScript libraries
39
copyVendor('js/*/*.js', 'js/vendor');
40
41
// Copy Twitter Bootstrap
42
copyVendor('twbs/bootstrap/dist/js/*.js', 'js/vendor');
43
copyVendor('twbs/bootstrap/dist/css/*', 'css');
44
copyVendor('twbs/bootstrap/dist/fonts/*', 'fonts');
45
46
// Copy Font Awesome
47
copyVendor('fortawesome/font-awesome/css/*', 'css');
48
copyVendor('fortawesome/font-awesome/fonts/*', 'fonts');
49