BackupCommandAbstract   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 70
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getBackupInstance() 0 7 1
handle() 0 1 ?
A getConfig() 0 4 1
1
<?php
2
3
namespace Cornford\Backup\Commands;
4
5
use Cornford\Backup\BackupFactory;
6
use Cornford\Backup\Contracts\BackupEngineInterface;
7
use Cornford\Backup\Contracts\BackupInterface;
8
use Cornford\Backup\Contracts\BackupCommandInterface;
9
use Illuminate\Console\Command;
10
use Illuminate\Config\Repository as Config;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
abstract class BackupCommandAbstract extends Command implements BackupCommandInterface
15
{
16
    /**
17
     * Backup factory.
18
     *
19
     * @var BackupFactory
20
     */
21
    protected $backupFactory;
22
23
    /**
24
     * Config instance.
25
     *
26
     * @var Config
27
     */
28
    protected $configInstance;
29
30
    /**
31
     * Backup instance.
32
     *
33
     * @var BackupInterface
34
     */
35
    protected $backupInstance;
36
37
    /**
38
     * Base command constructor.
39
     *
40
     * @param BackupFactory $backupFactory
41
     * @param Config        $configInstance
42
     */
43
    public function __construct(BackupFactory $backupFactory, Config $configInstance)
44
    {
45
        parent::__construct();
46
        $this->backupFactory = $backupFactory;
47
        $this->configInstance = $configInstance;
48
    }
49
50
    /**
51
     * Get a backup instance.
52
     *
53
     * @param string $database
54
     *
55
     * @return BackupInterface
56
     */
57
    public function getBackupInstance($database = null): BackupInterface
58
    {
59
        $configuration = array_merge($this->getConfig('database'), $this->getConfig('backup::config'));
60
        $this->backupInstance = $this->backupFactory->build($configuration, $database);
61
62
        return $this->backupInstance;
63
    }
64
65
    /**
66
     * Handle.
67
     *
68
     * @return void
69
     */
70
    abstract public function handle(): void;
71
72
    /**
73
     * Get config by name.
74
     *
75
     * @param string $name
76
     *
77
     * @return array|string
78
     */
79
    protected function getConfig($name)
80
    {
81
        return $this->configInstance->get($name);
82
    }
83
}
84