Completed
Push — master ( 95cf34...39f396 )
by Avtandil
05:52
created

LogClear   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 24 6
1
<?php
2
/*
3
 * This file is part of the Laravel Lodash package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
12
namespace Longman\LaravelLodash\Commands;
13
14
use Illuminate\Console\Command;
15
use Illuminate\Console\ConfirmableTrait;
16
use Illuminate\Filesystem\Filesystem;
17
18
class LogClear extends Command
19
{
20
    use ConfirmableTrait;
21
22
    /**
23
     * The name and signature of the console command.
24
     *
25
     * @var string
26
     */
27
    protected $signature = 'log:clear {--force : Force the operation to run when in production.}';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Clear log files';
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle(Filesystem $filesystem)
42
    {
43
        if (! $this->confirmToProceed('Application In Production! Will be deleted all log files from storage/log folder!')) {
44
            return;
45
        }
46
47
        $logFiles = $filesystem->allFiles(storage_path('logs'));
48
        if (! $logFiles) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $logFiles of type Symfony\Component\Finder\SplFileInfo[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
49
            $this->comment('Log files does not found in path ' . storage_path('logs'));
50
51
            return;
52
        }
53
54
        foreach ($logFiles as $file) {
55
            if ($file->getExtension() !== 'log') {
56
                continue;
57
            }
58
59
            $status = $filesystem->delete($file->getRealPath());
60
            if ($status) {
61
                $this->info('Successfully deleted: ' . $file);
62
            }
63
        }
64
    }
65
}
66