Passed
Push — master ( a36b47...022fca )
by Caen
09:56 queued 03:14
created

makeDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
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
    function backupDirectory(string $directory): void
16
    {
17
        if (file_exists($directory)) {
18
            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

18
            File::copyDirectory($directory, $directory.'-bak', /** @scrutinizer ignore-type */ true);
Loading history...
19
        }
20
    }
21
}
22
23
if (! function_exists('restoreDirectory')) {
24
    function restoreDirectory(string $directory): void
25
    {
26
        if (file_exists($directory.'-bak')) {
27
            File::moveDirectory($directory.'-bak', $directory, true);
28
            File::deleteDirectory($directory.'-bak');
29
        }
30
    }
31
}
32
33
if (! function_exists('deleteDirectory')) {
34
    function deleteDirectory(string $directory): void
35
    {
36
        if (file_exists($directory)) {
37
            File::deleteDirectory($directory);
38
        }
39
    }
40
}
41
42
if (! function_exists('makeDirectory')) {
43
    function makeDirectory(string $directory): void
44
    {
45
        if (file_exists($directory)) {
46
            File::makeDirectory($directory);
47
        }
48
    }
49
}
50
51
if (! function_exists('unlinkUnlessDefault')) {
52
    function unlinkUnlessDefault(string $filepath): void
53
    {
54
        $protected = [
55
            'app.css',
56
            'index.blade.php',
57
            '404.blade.php',
58
            '.gitkeep',
59
        ];
60
61
        if (! in_array(basename($filepath), $protected)) {
62
            unlink($filepath);
63
        }
64
    }
65
}
66
67
if (! function_exists('strip_newlines')) {
68
    function strip_newlines(string $string, bool $keepUnixEndings = false): string
69
    {
70
        if ($keepUnixEndings) {
71
            return str_replace("\r", '', $string);
72
        }
73
74
        return str_replace(["\r", "\n"], '', $string);
75
    }
76
}
77
78
if (! function_exists('strip_indentation')) {
79
    function strip_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string
80
    {
81
        $indentation = $indentUsingSpaces ? str_repeat(' ', $indentationLength) : "\t";
82
83
        return str_replace($indentation, '', $string);
84
    }
85
}
86
87
if (! function_exists('strip_newlines_and_indentation')) {
88
    function strip_newlines_and_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string
89
    {
90
        return strip_newlines(strip_indentation($string, $indentUsingSpaces, $indentationLength));
91
    }
92
}
93