Completed
Push — master ( eeca44...c0d702 )
by Jasper
06:01 queued 40s
created

ClearStaticCache::clearStorageDirectory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0185
1
<?php
2
3
namespace Swis\LaravelStaticRequestCache\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
8
class ClearStaticCache extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'static-html-cache:clear';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Clear static html-response caches';
23
24
    /**
25
     * @var Filesystem
26
     */
27
    private $files;
28
29
    /**
30
     * Create a new command instance.
31
     *
32
     * @param Filesystem $files
33
     */
34 4
    public function __construct(Filesystem $files)
35
    {
36 4
        $this->files = $files;
37
38 4
        parent::__construct();
39 4
    }
40
41
    /**
42
     * Execute the console command.
43
     */
44 4
    public function handle()
45
    {
46 4
        $this->clearStorageDirectory(config('static-html-cache.cache_path_prefix'));
47
48 4
        $this->info('Static caches cleared!');
49 4
    }
50
51
    /**
52
     * @param string $path
53
     */
54 4
    private function clearStorageDirectory(string $path)
55
    {
56 4
        $path = public_path($path);
57 4
        $this->comment("Clearing `{$path}`…");
58
59 4
        if ($this->files->isDirectory($path)) {
60 4
            $this->files->deleteDirectory($path, true);
61
        }
62 4
    }
63
}
64