Installer::copyConfiguration()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 8.8333
c 0
b 0
f 0
cc 7
nc 5
nop 1
1
<?php
2
3
namespace lcds\composer;
4
5
class Installer
6
{
7
    /**
8
     * Post composer install event script.
9
     *
10
     * @param mixed $event composer event
11
     */
12
    public static function postInstall($event)
13
    {
14
        $params = $event->getComposer()->getPackage()->getExtra();
15
        if (isset($params[__METHOD__]) && is_array($params[__METHOD__])) {
16
            foreach ($params[__METHOD__] as $method => $args) {
17
                call_user_func_array([__CLASS__, $method], (array) $args);
18
            }
19
        }
20
    }
21
22
    /**
23
     * Copy configuration files on composer install script end.
24
     *
25
     * @param array $paths configuration files
26
     */
27
    public static function copyConfiguration(array $paths)
28
    {
29
        foreach ($paths as $from => $to) {
30
            echo 'copy '.$from.' '.$to.': ';
31
            if (is_dir($to) || is_file($to)) {
32
                echo 'destination file exists.'.PHP_EOL;
33
            } elseif (is_dir($from) || is_file($from)) {
34
                if (copy($from, $to)) {
35
                    echo 'done.'.PHP_EOL;
36
                } else {
37
                    echo 'error while copying file.'.PHP_EOL;
38
                }
39
            } else {
40
                echo 'file not found.'.PHP_EOL;
41
            }
42
        }
43
    }
44
}
45