MakeCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Arrilot\BitrixMigrations\Commands;
4
5
use Arrilot\BitrixMigrations\Migrator;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class MakeCommand extends AbstractCommand
10
{
11
    /**
12
     * Migrator instance.
13
     *
14
     * @var Migrator
15
     */
16
    protected $migrator;
17
18
    protected static $defaultName = 'make';
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param Migrator    $migrator
24
     * @param string|null $name
25
     */
26
    public function __construct(Migrator $migrator, $name = null)
27
    {
28
        $this->migrator = $migrator;
29
30
        parent::__construct($name);
31
    }
32
33
    /**
34
     * Configures the current command.
35
     */
36
    protected function configure()
37
    {
38
        $this->setDescription('Create a new migration file')
39
            ->addArgument(
40
                'name',
41
                InputArgument::REQUIRED,
42
                'The name of the migration'
43
            )
44
            ->addOption(
45
                'template',
46
                't',
47
                InputOption::VALUE_REQUIRED,
48
                'Migration template'
49
            )
50
            ->addOption(
51
                'directory',
52
                'd',
53
                InputOption::VALUE_REQUIRED,
54
                'Migration directory'
55
            );
56
    }
57
58
    /**
59
     * Execute the console command.
60
     *
61
     * @return null|int
62
     */
63
    protected function fire()
64
    {
65
        $migration = $this->migrator->createMigration(
66
            $this->input->getArgument('name'),
0 ignored issues
show
Bug introduced by
It seems like $this->input->getArgument('name') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, Arrilot\BitrixMigrations...ator::createMigration() 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...
67
            $this->input->getOption('template'),
68
            [],
69
            $this->input->getOption('directory')
70
        );
71
72
        $this->message("<info>Migration created:</info> {$migration}.php");
73
    }
74
}
75