Passed
Push — master ( 1451be...870e13 )
by Caen
05:30 queued 02:35
created

ResetsApplication   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 22
c 4
b 0
f 0
dl 0
loc 61
rs 10
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A resetPosts() 0 3 1
A restoreDefaultPages() 0 4 1
A withoutDefaultPages() 0 4 1
A resetMedia() 0 2 1
A resetPages() 0 4 1
A unlinkUnlessDefault() 0 11 2
A resetApplication() 0 7 1
A resetSite() 0 3 1
A resetDocs() 0 3 1
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->resetMedia();
0 ignored issues
show
Deprecated Code introduced by
The function Hyde\Testing\ResetsApplication::resetMedia() has been deprecated: unless applicable usages are found ( Ignorable by Annotation )

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

14
        /** @scrutinizer ignore-deprecated */ $this->resetMedia();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
15
        $this->resetPages();
16
        $this->resetPosts();
17
        $this->resetDocs();
18
        $this->resetSite();
19
    }
20
21
    /** @deprecated unless applicable usages are found */
22
    protected function resetMedia(): void
23
    {
24
        //
25
    }
26
27
    protected function resetPages(): void
28
    {
29
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_pages/*.md')));
30
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_pages/*.blade.php')));
31
    }
32
33
    protected function resetPosts(): void
34
    {
35
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_posts/*.md')));
36
    }
37
38
    protected function resetDocs(): void
39
    {
40
        array_map('\Hyde\Testing\TestCase::unlinkUnlessDefault', glob(Hyde::path('_docs/*.md')));
41
    }
42
43
    protected function resetSite(): void
44
    {
45
        Filesystem::cleanDirectory('_site');
46
    }
47
48
    protected function withoutDefaultPages(): void
49
    {
50
        Hyde::unlink('_pages/404.blade.php');
51
        Hyde::unlink('_pages/index.blade.php');
52
    }
53
54
    protected function restoreDefaultPages(): void
55
    {
56
        copy(Hyde::vendorPath('resources/views/homepages/welcome.blade.php'), Hyde::path('_pages/index.blade.php'));
57
        copy(Hyde::vendorPath('resources/views/pages/404.blade.php'), Hyde::path('_pages/404.blade.php'));
58
    }
59
60
    protected static function unlinkUnlessDefault(string $filepath): void
61
    {
62
        $protected = [
63
            'app.css',
64
            'index.blade.php',
65
            '404.blade.php',
66
            '.gitkeep',
67
        ];
68
69
        if (! in_array(basename($filepath), $protected)) {
70
            unlink($filepath);
71
        }
72
    }
73
}
74