Passed
Push — master ( 7dcd3c...6c7933 )
by Caen
03:11 queued 12s
created

strip_indentation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
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 5
rs 10
cc 2
nc 2
nop 3
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('unlinkUnlessDefault')) {
43
    function unlinkUnlessDefault(string $filepath): void
44
    {
45
        $protected = [
46
            'app.css',
47
            'index.blade.php',
48
            '404.blade.php',
49
            '.gitkeep',
50
        ];
51
52
        if (! in_array(basename($filepath), $protected)) {
53
            unlink($filepath);
54
        }
55
    }
56
}
57
58
if (! function_exists('strip_newlines')) {
59
    function strip_newlines(string $string, bool $keepUnixEndings = false): string
60
    {
61
        if ($keepUnixEndings) {
62
            return str_replace("\r", '', $string);
63
        }
64
65
        return str_replace(["\r", "\n"], '', $string);
66
    }
67
}
68
69
if (! function_exists('strip_indentation')) {
70
    function strip_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string
71
    {
72
        $indentation = $indentUsingSpaces ? str_repeat(' ', $indentationLength) : "\t";
73
74
        return str_replace($indentation, '', $string);
75
    }
76
}
77
78
if (! function_exists('strip_newlines_and_indentation')) {
79
    function strip_newlines_and_indentation(string $string, bool $indentUsingSpaces = true, int $indentationLength = 4): string
80
    {
81
        return strip_newlines(strip_indentation($string, $indentUsingSpaces, $indentationLength));
82
    }
83
}
84