These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\Backup\Commands; |
||
4 | |||
5 | use Exception; |
||
6 | use Spatie\Backup\Events\CleanupHasFailed; |
||
7 | use Spatie\Backup\Tasks\Cleanup\CleanupJob; |
||
8 | use Spatie\Backup\Tasks\Cleanup\CleanupStrategy; |
||
9 | use Spatie\Backup\BackupDestination\BackupDestinationFactory; |
||
10 | |||
11 | class CleanupCommand extends BaseCommand |
||
12 | { |
||
13 | /** @var string */ |
||
14 | protected $signature = 'backup:clean {--disable-notifications}'; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $description = 'Remove all backups older than specified number of days in config.'; |
||
18 | |||
19 | /** @var \Spatie\Backup\Tasks\Cleanup\CleanupStrategy */ |
||
20 | protected $strategy; |
||
21 | |||
22 | public function __construct(CleanupStrategy $strategy) |
||
23 | { |
||
24 | parent::__construct(); |
||
25 | |||
26 | $this->strategy = $strategy; |
||
27 | } |
||
28 | |||
29 | public function handle() |
||
30 | { |
||
31 | consoleOutput()->comment('Starting cleanup...'); |
||
0 ignored issues
–
show
|
|||
32 | |||
33 | $disableNotifications = $this->option('disable-notifications'); |
||
34 | |||
35 | try { |
||
36 | $config = config('backup'); |
||
37 | |||
38 | $backupDestinations = BackupDestinationFactory::createFromArray($config['backup']); |
||
39 | |||
40 | $cleanupJob = new CleanupJob($backupDestinations, $this->strategy, $disableNotifications); |
||
41 | |||
42 | $cleanupJob->run(); |
||
43 | |||
44 | consoleOutput()->comment('Cleanup completed!'); |
||
0 ignored issues
–
show
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 This is often the case, when 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 { }
![]() |
|||
45 | } catch (Exception $exception) { |
||
46 | if (! $disableNotifications) { |
||
47 | event(new CleanupHasFailed($exception)); |
||
48 | } |
||
49 | |||
50 | return 1; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 |
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: