Completed
Pull Request — master (#1)
by Rougin
02:21
created

ResetCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Rougin\Refinery\Commands;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
/**
9
 * Reset Command
10
 *
11
 * Resets all migrations.
12
 *
13
 * @package Refinery
14
 * @author  Rougin Royce Gutib <[email protected]>
15
 */
16
class ResetCommand extends AbstractCommand
17
{
18
    /**
19
     * Sets the configurations of the specified command.
20
     *
21
     * @return void
22
     */
23 3
    protected function configure()
24
    {
25 3
        $this->setName('reset')->setDescription('Resets all migrations');
26 3
    }
27
28
    /**
29
     * Executes the command.
30
     *
31
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
32
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
33
     * @return object|\Symfony\Component\Console\Output\OutputInterface
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $current = $this->getLatestVersion();
38
39
        if ($current <= 0) {
40
            return $output->writeln('<info>Database\'s version is now in 0.</info>');
41
        }
42
43
        $this->toggleMigration(true);
44
        $this->changeVersion($current, 0);
45
46
        $this->codeigniter->load->library('migration');
0 ignored issues
show
Bug introduced by
The property load does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
        $this->codeigniter->migration->current();
0 ignored issues
show
Bug introduced by
The property migration does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
48
49
        $this->toggleMigration();
50
51
        return $output->writeln('<info>Database has been resetted.</info>');
52
    }
53
}
54