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

BackupCommand::getAllFilesToBeBackedUp()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 1 Features 4
Metric Value
c 8
b 1
f 4
dl 0
loc 20
rs 8.8571
cc 5
eloc 12
nc 4
nop 0
1
<?php
2
3
namespace Spatie\Backup\Commands;
4
5
use Spatie\Backup\Events\BackupHasFailed;
6
use Spatie\Backup\Exceptions\InvalidCommand;
7
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
8
use Exception;
9
10
class BackupCommand extends BaseCommand
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $signature = 'backup:run {--only-db} {--only-files}';
16
17
    /**
18
     * @var string
19
     */
20
    protected $description = 'Run the backup.';
21
22
    public function handle()
23
    {
24
        consoleOutput()->comment('Starting backup.');
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...
25
26
        try {
27
            $this->guardAgainstInvalidOptions();
28
29
            $backupJob = BackupJobFactory::createFromArray(config('laravel-backup'));
30
31
            if ($this->option('only-db')) {
32
                $backupJob->doNotBackupFilesystem();
33
            }
34
35
            if ($this->option('only-files')) {
36
                $backupJob->doNotBackupDatabases();
37
            }
38
39
            $backupJob->run();
40
41
            consoleOutput()->comment('Backup 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...
42
        } catch (Exception $exception) {
43
            event(new BackupHasFailed($exception));
44
45
            throw $exception;
46
        }
47
    }
48
49
    protected function guardAgainstInvalidOptions()
50
    {
51
        if ($this->option('only-db') && $this->option('only-files')) {
52
            throw InvalidCommand::create('Cannot use only-db and only-files together');
53
        }
54
    }
55
}
56