Completed
Push — master ( 3dec7f...3bd0ad )
by Rougin
04:25
created

ResetCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2.032

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 22
ccs 12
cts 15
cp 0.8
rs 9.2
cc 2
eloc 12
nc 2
nop 2
crap 2.032
1
<?php
2
3
namespace Rougin\Refinery\Commands;
4
5
use Symfony\Component\Console\Input\InputOption;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
use Rougin\SparkPlug\Instance;
11
use Rougin\Refinery\Common\MigrationHelper;
12
13
/**
14
 * Reset Migration Command
15
 *
16
 * Resets all migrations.
17
 *
18
 * @package Refinery
19
 * @author  Rougin Royce Gutib <[email protected]>
20
 */
21
class ResetCommand extends AbstractCommand
22
{
23
    /**
24
     * Sets the configurations of the specified command.
25
     *
26
     * @return void
27
     */
28 10
    protected function configure()
29
    {
30 10
        $this->setName('reset')
31 10
            ->setDescription('Resets all migrations');
32 10
    }
33
34
    /**
35
     * Executes the command.
36
     *
37
     * @param  InputInterface  $input
38
     * @param  OutputInterface $output
39
     * @return object|OutputInterface
40
     */
41 2
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43 2
        $migration = file_get_contents(APPPATH . '/config/migration.php');
44 2
        $current = MigrationHelper::getLatestVersion($migration);
45
46 2
        if ($current <= 0) {
47 2
            $message = 'Database\'s version is now in 0.';
48
49 2
            return $output->writeln('<info>' . $message . '</info>');
50
        }
51
52
        // Enables migration and change the current version to 0
53 2
        MigrationHelper::toggleMigration(true);
54 2
        MigrationHelper::changeVersion($current, 0);
55
56 2
        $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...
57 2
        $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...
58
59 2
        MigrationHelper::toggleMigration();
60
61 2
        return $output->writeln('<info>Database has been resetted.</info>');
62
    }
63
}
64