Passed
Push — master ( df324d...7773d7 )
by Caen
03:06 queued 14s
created

backup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\File;
4
5
if (! function_exists('unlinkIfExists')) {
6
    function unlinkIfExists(string $filepath): void
7
    {
8
        if (file_exists($filepath)) {
9
            unlink($filepath);
10
        }
11
    }
12
}
13
14
if (! function_exists('backupDirectory')) {
15
    /** @deprecated v0.60.x - You should not run tests in a production environment. */
16
    function backupDirectory(string $directory): void
17
    {
18
        if (file_exists($directory)) {
19
            File::copyDirectory($directory, $directory.'-bak', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer|null expected by parameter $options of Illuminate\Support\Facades\File::copyDirectory(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
            File::copyDirectory($directory, $directory.'-bak', /** @scrutinizer ignore-type */ true);
Loading history...
20
        }
21
    }
22
}
23
24
if (! function_exists('restoreDirectory')) {
25
    /** @deprecated v0.60.x - You should not run tests in a production environment. */
26
    function restoreDirectory(string $directory): void
27
    {
28
        if (file_exists($directory.'-bak')) {
29
            File::moveDirectory($directory.'-bak', $directory, true);
30
            File::deleteDirectory($directory.'-bak');
31
        }
32
    }
33
}
34
35
if (! function_exists('deleteDirectory')) {
36
    function deleteDirectory(string $directory): void
37
    {
38
        if (file_exists($directory)) {
39
            File::deleteDirectory($directory);
40
        }
41
    }
42
}
43
44
if (! function_exists('unlinkUnlessDefault')) {
45
    function unlinkUnlessDefault(string $filepath): void
46
    {
47
        $protected = [
48
            'app.css',
49
            'index.blade.php',
50
            '404.blade.php',
51
            '.gitkeep',
52
        ];
53
54
        if (! in_array(basename($filepath), $protected)) {
55
            unlink($filepath);
56
        }
57
    }
58
}
59