Completed
Push — dev ( 6d8737...fe3822 )
by Zach
02:19
created

MigrateRefresh::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Commands;
4
5
use Yarak\DB\Seeders\SeedRunner;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class MigrateRefresh extends YarakCommand
9
{
10
    /**
11
     * Configure the command.
12
     */
13
    protected function configure()
14
    {
15
        $this->setName('migrate:refresh')
16
            ->setDescription('Refresh the database.')
17
            ->setHelp(
18
                'This command allows you to refresh the database by rolling back and re-running all migrations.'
19
            )
20
            ->addSeed()
21
            ->addSeedClass();
22
    }
23
24
    /**
25
     * Add seed option.
26
     */
27
    protected function addSeed()
28
    {
29
        return $this->addOption(
30
            'seed',
31
            null,
32
            InputOption::VALUE_NONE,
33
            'Seed the database after refreshing.'
34
        );
35
    }
36
37
    /**
38
     * Add seed class option.
39
     */
40
    protected function addSeedClass()
41
    {
42
        return $this->addOption(
43
            'class',
44
            null,
45
            InputOption::VALUE_OPTIONAL,
46
            'The name of the seeder class to run.',
47
            'DatabaseSeeder'
48
        );
49
    }
50
51
    /**
52
     * Handle the command.
53
     */
54
    protected function handle()
55
    {
56
        $this->getMigrator($this->getOutput())->refresh();
57
58
        if ($this->option('seed')) {
59
            $seedRunner = new SeedRunner($this->getOutput());
60
61
            $seedRunner->run($this->option('class'));
1 ignored issue
show
Bug introduced by
It seems like $this->option('class') targeting Yarak\Console\Command::option() can also be of type array; however, Yarak\DB\Seeders\SeedRunner::run() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
62
        }
63
    }
64
}
65