ZfPhinxService::runMigrateCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ZfPhinx\Service;
4
5
use Phinx\Config\Config;
6
use Phinx\Console\Command\AbstractCommand;
7
use Phinx\Console\Command\Create;
8
use Phinx\Console\Command\Migrate;
9
use Phinx\Console\Command\Rollback;
10
use Phinx\Console\Command\Status;
11
use Phinx\Console\PhinxApplication;
12
use Symfony\Component\Console\Input\ArgvInput;
13
use Symfony\Component\Console\Output\ConsoleOutput;
14
use ZfPhinx\Command\Test;
15
16
/**
17
 * Phinx service
18
 */
19
class ZfPhinxService
20
{
21
    /**
22
     * Phinx application
23
     *
24
     * @var PhinxApplication
25
     */
26
    private $phinxApplication;
27
28
    /**
29
     * Phinx application config
30
     *
31
     * @var Config
32
     */
33
    private $config;
34
35
    /**
36
     * @param PhinxApplication $phinxApplication
37
     * @param Config           $config
38
     */
39 1
    public function __construct(PhinxApplication $phinxApplication, Config $config)
40
    {
41 1
        $this->phinxApplication = $phinxApplication;
42 1
        $this->config           = $config;
43 1
    }
44
45
    /**
46
     * Executes 'Test' command
47
     *
48
     * @param  array $argv
49
     * @return void
50
     */
51
    public function runTestCommand(array $argv)
52
    {
53
        $this->runNamedCommand(new Test(), $argv);
54
    }
55
56
    /**
57
     * Executes 'Crete' command
58
     *
59
     * @param  array $argv
60
     * @return void
61
     */
62
    public function runCreateCommand(array $argv)
63
    {
64
        $this->runNamedCommand(new Create(), $argv);
65
    }
66
67
    /**
68
     * Executes 'Migrate' command
69
     *
70
     * @param  array $argv
71
     * @return void
72
     */
73
    public function runMigrateCommand(array $argv)
74
    {
75
        $this->runNamedCommand(new Migrate(), $argv);
76
    }
77
78
    /**
79
     * Executes 'Rollback' command
80
     *
81
     * @param  array $argv
82
     * @return void
83
     */
84
    public function runRollbackCommand(array $argv)
85
    {
86
        $this->runNamedCommand(new Rollback(), $argv);
87
    }
88
89
    /**
90
     * Executes 'Status' command
91
     *
92
     * @param  array $argv
93
     * @return void
94
     */
95
    public function runStatusCommand(array $argv)
96
    {
97
        $this->runNamedCommand(new Status(), $argv);
98
    }
99
100
    /**
101
     * Executes given Phinx command
102
     *
103
     * @param  AbstractCommand $command
104
     * @param  array           $argv
105
     * @return void
106
     */
107
    private function runNamedCommand(AbstractCommand $command, array $argv)
108
    {
109
        $command->setConfig($this->config);
110
111
        $application = $this->getPhinxApplication();
112
        $application->add($command);
113
        $application->run(new ArgvInput($argv), new ConsoleOutput());
114
    }
115
116
    /**
117
     * Gets Phinx application
118
     *
119
     * @return PhinxApplication
120
     */
121
    private function getPhinxApplication()
122
    {
123
        return clone $this->phinxApplication;
124
    }
125
}
126