PhinxController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ZfPhinx\Controller;
4
5
use Zend\Console\ColorInterface;
6
use Zend\Mvc\Console\Controller\AbstractConsoleController;
7
use ZfPhinx\Module;
8
use ZfPhinx\Service\ZfPhinxService;
9
10
/**
11
 * Phinx console controller
12
 */
13
class PhinxController extends AbstractConsoleController
14
{
15
    /**
16
     * Phinx service
17
     *
18
     * @var ZfPhinxService
19
     */
20
    private $phinxService;
21
22
    /**
23
     * @param ZfPhinxService $phinxService
24
     */
25 1
    public function __construct(ZfPhinxService $phinxService)
26
    {
27 1
        $this->phinxService = $phinxService;
28 1
    }
29
30
    /**
31
     * Runs 'Test' command
32
     *
33
     * @return void
34
     */
35
    public function testAction()
36
    {
37
        $this->writeModuleInfo();
38
        $this->getPhinxService()->runTestCommand($this->getArgvArray());
39
    }
40
41
    /**
42
     * Runs 'Create' command
43
     *
44
     * @return void
45
     */
46
    public function createAction()
47
    {
48
        $this->writeModuleInfo();
49
        $this->getPhinxService()->runCreateCommand($this->getArgvArray());
50
    }
51
52
    /**
53
     * Runs 'Migrate' command
54
     *
55
     * @return void
56
     */
57
    public function migrateAction()
58
    {
59
        $this->writeModuleInfo();
60
        $this->getPhinxService()->runMigrateCommand($this->getArgvArray());
61
    }
62
63
    /**
64
     * Runs 'Rollback' command
65
     *
66
     * @return void
67
     */
68
    public function rollbackAction()
69
    {
70
        $this->writeModuleInfo();
71
        $this->getPhinxService()->runRollbackCommand($this->getArgvArray());
72
    }
73
74
    /**
75
     * Runs 'Status' command
76
     *
77
     * @return void
78
     */
79
    public function statusAction()
80
    {
81
        $this->writeModuleInfo();
82
        $this->getPhinxService()->runStatusCommand($this->getArgvArray());
83
    }
84
85
    /**
86
     * Gets Phinx service
87
     *
88
     * @return ZfPhinxService
89
     */
90
    private function getPhinxService()
91
    {
92
        return $this->phinxService;
93
    }
94
95
    /**
96
     * Get console command arguments
97
     *
98
     * @return array
99
     */
100
    private function getArgvArray()
101
    {
102
        return (array) $this->getRequest()->getContent();
103
    }
104
105
    /**
106
     * Writes copyright & version into console
107
     *
108
     * @return void
109
     */
110
    private function writeModuleInfo()
111
    {
112
        $console = $this->getConsole();
113
        $console->write('ZfPhinx by Alexey Buyanov. ', ColorInterface::GREEN);
114
        $console->write('version: ', ColorInterface::WHITE);
115
        $console->writeLine(Module::MODULE_VERSION, ColorInterface::YELLOW);
116
    }
117
}
118