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

ResetCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.008

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1.008
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