Publish   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
c 1
b 0
f 1
dl 0
loc 38
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A delTree() 0 13 4
A handle() 0 16 3
1
<?php namespace GeneaLabs\LaravelImagery\Console\Commands;
2
3
use File;
4
use GeneaLabs\LaravelImagery\Providers\LaravelImageryService;
5
use Illuminate\Console\Command;
6
use Illuminate\Contracts\Console\Kernel;
7
8
class Publish extends Command
9
{
10
    protected $signature = 'imagery:publish {--assets} {--config}';
11
    protected $description = 'Publish various assets of the Laravel Imagery package.';
12
13
    public function handle()
14
    {
15
        if ($this->option('assets')) {
16
            $this->delTree(public_path('genealabs-laravel-imagery'));
17
            $this->call('vendor:publish', [
18
                '--provider' => LaravelImageryService::class,
19
                '--tag' => ['assets'],
20
                '--force' => true,
21
            ]);
22
        }
23
24
        if ($this->option('config')) {
25
            $this->call('vendor:publish', [
26
                '--provider' => LaravelImageryService::class,
27
                '--tag' => ['config'],
28
                '--force' => true,
29
            ]);
30
        }
31
    }
32
33
    private function delTree($folder)
34
    {
35
        if (! is_dir($folder)) {
36
            return false;
37
        }
38
39
        $files = array_diff(scandir($folder), ['.','..']);
0 ignored issues
show
Bug introduced by
It seems like scandir($folder) can also be of type false; however, parameter $array1 of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $files = array_diff(/** @scrutinizer ignore-type */ scandir($folder), ['.','..']);
Loading history...
40
41
        foreach ($files as $file) {
42
            is_dir("$folder/$file") ? $this->delTree("$folder/$file") : unlink("$folder/$file");
43
        }
44
45
        return rmdir($folder);
46
    }
47
}
48