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

ResetCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 80%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 3
c 4
b 1
f 1
lcom 1
cbo 4
dl 0
loc 43
ccs 16
cts 20
cp 0.8
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 22 2
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