Completed
Push — master ( f62f21...f72c97 )
by Freek
05:09
created

CleanupCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 12
Bugs 2 Features 3
Metric Value
wmc 2
c 12
b 2
f 3
lcom 0
cbo 4
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 2
1
<?php
2
3
namespace Spatie\Backup\Commands;
4
5
use Spatie\Backup\BackupDestination\BackupDestinationFactory;
6
use Spatie\Backup\Events\CleanupHasFailed;
7
use Spatie\Backup\Tasks\Cleanup\CleanupJob;
8
9
class CleanupCommand extends BaseCommand
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $signature = 'backup:clean';
15
16
    /**
17
     * @var string
18
     */
19
    protected $description = 'Remove all backups older than specified number of days in config.';
20
21
    public function handle()
22
    {
23
        consoleOutput()->comment('Starting cleanup.');
0 ignored issues
show
Documentation Bug introduced by
The method comment does not exist on object<Spatie\Backup\Helpers\ConsoleOutput>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
24
25
        try {
26
            $config = config('laravel-backup');
27
28
            $backupDestinations = BackupDestinationFactory::createFromArray($config['backup']);
29
30
            $strategy = app($config['cleanup']['strategy']);
31
32
            $cleanupJob = new CleanupJob($backupDestinations, $strategy);
33
34
            $cleanupJob->run();
35
36
            consoleOutput()->comment('Cleanup completed!');
0 ignored issues
show
Documentation Bug introduced by
The method comment does not exist on object<Spatie\Backup\Helpers\ConsoleOutput>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
37
        } catch (Exception $exception) {
0 ignored issues
show
Bug introduced by
The class Spatie\Backup\Commands\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
38
            event(new CleanupHasFailed($exception));
39
        }
40
    }
41
}
42