ClearCacheCommand::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 0
1
<?php
2
3
namespace Scaffolder\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\File;
7
8
class ClearCacheCommand extends Command
9
{
10
    protected $signature = 'scaffolder:clear {what=all}';
11
12
    protected $description = 'Clear generated files like cache, json, drafts';
13
14
    /**
15
     * Execute the Command.
16
     */
17
    public function handle()
18
    {
19
       
20
21
        switch ($this->argument('what')) {
22
            case 'cache':
23
                $this->handleCache();
24
                break;
25
26
            case 'drafts':
27
                $this->handleBlade();
0 ignored issues
show
Bug introduced by
The method handleBlade() does not exist on Scaffolder\Commands\ClearCacheCommand. Did you maybe mean handle()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
28
                break;
29
            
30
            default:
31
                $this->handleCache();
32
                $this->handleDrafts();
33
                break;
34
        }
35
36
        
37
    }
38
39
    /**
40
     * Execute the command for compiled cache files.
41
     */
42
    public function handleCache()
43
    {
44
        // Get the compiled files
45
        $compiledFiles = File::glob(base_path('scaffolder-config/cache/*.scf'));
46
47
        // Start progress bar
48
        $this->output->progressStart(count($compiledFiles));
49
50
        foreach ($compiledFiles as $compiledFile)
51
        {
52
            File::delete($compiledFile);
53
54
            // Advance progress
55
            $this->output->progressAdvance();
56
        }
57
58
        // Finish progress
59
        $this->output->progressFinish();
60
61
        $this->info('Cache cleared');
62
    }
63
64
65
    /**
66
     * Execute the command for drafts files and folder.
67
     */
68
    public function handleDrafts()
69
    {
70
        $success = File::cleanDirectory(base_path('drafts'));
0 ignored issues
show
Unused Code introduced by
$success is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
71
72
        $this->info('Drafts cleared');
73
    }
74
}