Completed
Push — dev ( 4deee6...a8b68f )
by Zach
02:10
created

MigrateRefresh::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 9.4285
1
<?php
2
3
namespace Yarak\Commands;
4
5
use Yarak\Output\SymfonyOutput;
6
use Yarak\DB\Seeders\SeedRunner;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class MigrateRefresh extends YarakCommand
12
{
13
    /**
14
     * Configure the command.
15
     */
16
    protected function configure()
17
    {
18
        $this->setName('migrate:refresh')
19
            ->setDescription('Refresh the database.')
20
            ->setHelp(
21
                'This command allows you to refresh the database by rolling back and re-running all migrations.'
22
            )
23
            ->addSeed()
24
            ->addSeedClass();
25
    }
26
27
    /**
28
     * Add seed option.
29
     */
30
    protected function addSeed()
31
    {
32
        return $this->addOption(
33
            'seed',
34
            null,
35
            InputOption::VALUE_NONE,
36
            'Seed the database after refreshing.'
37
        );
38
    }
39
40
    /**
41
     * Add seed class option.
42
     */
43
    protected function addSeedClass()
44
    {
45
        return $this->addOption(
46
            'class',
47
            null,
48
            InputOption::VALUE_OPTIONAL,
49
            'The name of the seeder class to run.',
50
            'DatabaseSeeder'
51
        );
52
    }
53
54
    /**
55
     * Execute the command.
56
     *
57
     * @param InputInterface  $input
58
     * @param OutputInterface $output
59
     */
60
    protected function execute(InputInterface $input, OutputInterface $output)
61
    {
62
        $symfonyOutput = new SymfonyOutput($output);
63
64
        $this->getMigrator($symfonyOutput)->refresh();
65
66
        if ($input->getOption('seed')) {
67
            $seedRunner = new SeedRunner($symfonyOutput);
68
69
            $seedRunner->run($input->getOption('class'));
70
        }
71
    }
72
}
73