PurgeFilesCommand::purgeDebuggingFiles()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 17
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 10
cc 4
nc 3
nop 1
crap 20
1
<?php
2
3
namespace LaravelDuskReporter\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\File;
7
use LaravelDuskReporter\LaravelDuskReporter;
8
9
class PurgeFilesCommand extends Command
10
{
11
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'dusk-reporter:purge {--path=} {--y|yes}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Purge dusk report directory';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function handle()
32
    {
33
        if ($this->option('path')) {
34
            $this->purgeDebuggingFiles($this->option('path'));
35
36
            return 0;
37
        }
38
39
        $this->purgeDebuggingFiles(
40
            LaravelDuskReporter::storeBuildAt()
41
        );
42
43
        return 0;
44
    }
45
46
    /**
47
     * Purge report folder.
48
     *
49
     * @param string $path
50
     * @param string $patterns
51
     *
52
     * @return void
53
     */
54
    protected function purgeDebuggingFiles($path)
55
    {
56
        if (!is_dir($path)) {
57
            $this->warn("Unable to purge missing directory [{$path}].");
58
59
            return;
60
        }
61
62
63
        if ($this->option('yes') || $this->confirm("Do you wish to remove directory with all content? {$path}")) {
64
            File::deleteDirectory($path);
65
            $this->info("Removed directory [{$path}].");
66
67
            return;
68
        }
69
70
        $this->warn("Skip removing directory [{$path}].");
71
    }
72
}
73