Test Failed
Push — master ( d08b1d...c7da01 )
by Filippo
14:13 queued 09:16
created

ClearChunks::deleteFolder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Jobtech\LaravelChunky\Commands;
4
5
use Illuminate\Console\Command;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Console\ConfirmableTrait;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\ConfirmableTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Jobtech\LaravelChunky\Contracts\ChunkyManager;
8
9
class ClearChunks extends Command
10
{
11
    use ConfirmableTrait;
12
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'chunky:clear
19
    {folder? : The chunk folder}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Delete all chunks and relative folder.';
27
28
    /**
29
     * @var \Jobtech\LaravelChunky\Contracts\ChunkyManager
30
     */
31
    private $manager;
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @return void
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * @param \Jobtech\LaravelChunky\Contracts\ChunkyManager $manager
47
     *
48
     * @return mixed
49
     */
50
    public function handle(ChunkyManager $manager)
51
    {
52
        $this->manager = $manager;
53
54
        if (! $this->confirmToProceed()) {
55
            return;
56
        }
57
58
        $root = $this->manager->chunksFolder();
59
        $folder = $this->argument('folder');
60
61
        if (! empty($folder)) {
62
            $root .= $folder;
63
            $this->deleteFolder($root);
64
65
            return;
66
        }
67
68
        $folders = $this->manager->chunksFilesystem()->chunkFolders();
69
        $bar = $this->output->createProgressBar(count($folders));
70
71
        $bar->start();
72
73
        foreach ($folders as $folder) {
74
            $this->deleteFolder($folder);
75
        }
76
77
        $bar->finish();
78
        $this->info('Chunks folders have been deleted!');
79
    }
80
81
    /**
82
     * @param string $folder
83
     */
84
    private function deleteFolder(string $folder)
85
    {
86
        if (! $this->manager->deleteChunks($folder)) {
87
            $this->error("An error occurred while deleting folder {$folder}");
88
89
            return;
90
        }
91
92
        $this->info("folder {$folder} has been deleted!");
93
    }
94
}
95