Completed
Pull Request — master (#10)
by
unknown
06:59
created

deleteDirectoriesIfOlderThanMinutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Spatie\DirectoryCleanup;
4
5
use Illuminate\Console\Command;
6
7
class DirectoryCleanupCommand extends Command
8
{
9
    /** @var string */
10
    protected $signature = 'clean:directories';
11
12
    /** @var string */
13
    protected $description = 'Clean up directories.';
14
15
    public function handle()
16
    {
17
        $this->comment('Cleaning directories...');
18
19
        $directories = collect(config('laravel-directory-cleanup.directories'));
20
21
        collect($directories)->each(function ($config, $directory) {
22
23
            if(isset($config['deleteFilesOlderThanMinutes'])) {
24
                $this->deleteFilesIfOlderThanMinutes($directory, $config['deleteFilesOlderThanMinutes']);
25
            }
26
27
            if(isset($config['deleteDirectoriesOlderThanMinutes'])) {
28
                $this->deleteDirectoriesIfOlderThanMinutes($directory, $config['deleteDirectoriesOlderThanMinutes']);
29
            }
30
31
        });
32
33
        $this->comment('All done!');
34
    }
35
36 View Code Duplication
    protected function deleteFilesIfOlderThanMinutes(string $directory, int $minutes)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $deletedFiles = app(DirectoryCleaner::class)
39
            ->setDirectory($directory)
40
            ->deleteFilesOlderThanMinutes($minutes);
41
42
        $this->info("Deleted {$deletedFiles->count()} file(s) from {$directory}.");
43
    }
44
45 View Code Duplication
    protected function deleteDirectoriesIfOlderThanMinutes(string $directory, int $minutes)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $deletedFiles = app(DirectoryCleaner::class)
48
            ->setDirectory($directory)
49
            ->deleteDirectoriesOlderThanMinutes($minutes);
50
51
        $this->info("Deleted {$deletedFiles->count()} folder(s) from {$directory}.");
52
    }
53
}
54