Passed
Push — master ( 524499...a3da55 )
by Caen
03:36 queued 12s
created

ResetsApplication::resetMedia()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Testing;
6
7
use Hyde\Facades\Filesystem;
8
use Hyde\Hyde;
9
10
trait ResetsApplication
11
{
12
    protected function resetApplication(): void
13
    {
14
        $this->resetPages();
15
        $this->resetPosts();
16
        $this->resetDocs();
17
        $this->resetSite();
18
    }
19
20
    protected function resetPages(): void
21
    {
22
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_pages/*.md')));
23
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_pages/*.blade.php')));
24
    }
25
26
    protected function resetPosts(): void
27
    {
28
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_posts/*.md')));
29
    }
30
31
    protected function resetDocs(): void
32
    {
33
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_docs/*.md')));
34
    }
35
36
    protected function resetSite(): void
37
    {
38
        Filesystem::cleanDirectory('_site');
39
    }
40
41
    protected function withoutDefaultPages(): void
42
    {
43
        Hyde::unlink('_pages/404.blade.php');
44
        Hyde::unlink('_pages/index.blade.php');
45
    }
46
47
    protected function restoreDefaultPages(): void
48
    {
49
        copy(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'), Hyde::path('_pages/index.blade.php'));
50
        copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php'));
51
    }
52
53
    protected static function unlinkUnlessDefault(string $filepath): void
54
    {
55
        $protected = [
56
            'app.css',
57
            'index.blade.php',
58
            '404.blade.php',
59
            '.gitkeep',
60
        ];
61
62
        if (! in_array(basename($filepath), $protected)) {
63
            unlink($filepath);
64
        }
65
    }
66
}
67