InstallCommand::fire()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Arrilot\BitrixMigrations\Commands;
4
5
use Arrilot\BitrixMigrations\Interfaces\DatabaseStorageInterface;
6
7
class InstallCommand extends AbstractCommand
8
{
9
    /**
10
     * Interface that gives us access to the database.
11
     *
12
     * @var DatabaseStorageInterface
13
     */
14
    protected $database;
15
16
    /**
17
     * Table in DB to store migrations that have been already run.
18
     *
19
     * @var string
20
     */
21
    protected $table;
22
23
    protected static $defaultName = 'install';
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param string                   $table
29
     * @param DatabaseStorageInterface $database
30
     * @param string|null              $name
31
     */
32
    public function __construct($table, DatabaseStorageInterface $database, $name = null)
33
    {
34
        $this->table = $table;
35
        $this->database = $database;
36
37
        parent::__construct($name);
38
    }
39
40
    /**
41
     * Configures the current command.
42
     */
43
    protected function configure()
44
    {
45
        $this->setDescription('Create the migration database table');
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @return null|int
52
     */
53
    protected function fire()
54
    {
55
        if ($this->database->checkMigrationTableExistence()) {
56
            $this->abort("Table \"{$this->table}\" already exists");
57
        }
58
59
        $this->database->createMigrationTable();
60
61
        $this->info('Migration table has been successfully created!');
62
    }
63
}
64