Completed
Push — develop ( caa1e7...4e03be )
by Martin
08:59
created

Controller::actionDump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * Yii2 Dumpling.
4
 *
5
 * This file contains Dumpling module.
6
 *
7
 * @author  Alexei Korotin <[email protected]>
8
 */
9
10
namespace herroffizier\yii2dumpling\commands;
11
12
use Yii;
13
use yii\helpers\Console;
14
15
/**
16
 * Dump or restore databases via console.
17
 */
18
class Controller extends \yii\console\Controller
19
{
20
    /**
21
     * Link to module.
22
     *
23
     * @var \herroffizier\yii2dumpling\Module
24
     */
25
    public $module;
26
27
    /**
28
     * Dump file name.
29
     *
30
     * @var string|null
31
     */
32
    public $file;
33
34
    /**
35
     * Database component.
36
     *
37
     * @var string|null
38
     */
39
    public $db;
40
41
    /**
42
     * @param string $actionID
43
     *
44
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
45
     * @codeCoverageIgnore
46
     */
47
    public function options($actionID)
48
    {
49
        return ['file', 'db'];
50
    }
51
52
    protected function getDumpFile()
53
    {
54
        return Yii::getAlias($this->file ?: $this->module->defaultDumpFile);
55
    }
56
57
    protected function getDbComponent()
58
    {
59
        return $this->db ?: $this->module->defaultDbComponent;
60
    }
61
62
    /**
63
     * Dump database.
64
     */
65 View Code Duplication
    public function actionDump()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $this->stdout('Dumping ');
68
        $this->stdout($this->getDbComponent(), Console::BOLD);
69
        $this->stdout(' to ');
70
        $this->stdout($this->getDumpFile(), Console::BOLD);
71
        $this->stdout('... ');
72
73
        $this->module->dump($this->file, $this->db);
74
75
        $this->stdout('done', Console::BOLD);
76
        $this->stdout("\n");
77
    }
78
79
    /**
80
     * Restore database.
81
     */
82 View Code Duplication
    public function actionRestore()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
    {
84
        $this->stdout('Dumping ');
85
        $this->stdout($this->getDbComponent(), Console::BOLD);
86
        $this->stdout(' from ');
87
        $this->stdout($this->getDumpFile(), Console::BOLD);
88
        $this->stdout('... ');
89
90
        $this->module->restore($this->file, $this->db);
91
92
        $this->stdout('done', Console::BOLD);
93
        $this->stdout("\n");
94
    }
95
}
96