Installer::copy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Part of CodeIgniter Cli
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2015 Kenji Suzuki
8
 * @link       https://github.com/kenjis/codeigniter-cli
9
 */
10
11
$installer = new Installer();
12
$installer->install();
13
14
class Installer
15
{
16
    public static function install()
17
    {
18
        self::recursiveCopy('vendor/kenjis/codeigniter-cli/config', 'config');
19
        
20
        @mkdir('tmp', 0755);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
21
        @mkdir('tmp/log', 0755);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
22
        
23
        self::copy('vendor/kenjis/codeigniter-cli/cli', 'cli');
24
        self::copy('vendor/kenjis/codeigniter-cli/ci_instance.php', 'ci_instance.php');
25
        
26
        chmod('cli', 0755);
27
    }
28
29
    private static function copy($src, $dst)
30
    {
31
        $success = copy($src, $dst);
32
        if ($success) {
33
            echo 'copied: ' . $dst . PHP_EOL;
34
        }
35
    }
36
37
    /**
38
     * Recursive Copy
39
     *
40
     * @param string $src
41
     * @param string $dst
42
     */
43
    private static function recursiveCopy($src, $dst)
44
    {
45
        @mkdir($dst, 0755);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
46
        
47
        $iterator = new \RecursiveIteratorIterator(
48
            new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS),
49
            \RecursiveIteratorIterator::SELF_FIRST
50
        );
51
        
52
        foreach ($iterator as $file) {
53
            if ($file->isDir()) {
54
                @mkdir($dst . '/' . $iterator->getSubPathName());
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
55
            } else {
56
                $success = copy($file, $dst . '/' . $iterator->getSubPathName());
57
                if ($success) {
58
                    echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL;
59
                }
60
            }
61
        }
62
    }
63
}
64