Completed
Push — master ( a49283...95f5a3 )
by Nekrasov
03:40
created

ArchiveCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Arrilot\BitrixMigrations\Commands;
4
5
use Arrilot\BitrixMigrations\Migrator;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class ArchiveCommand extends AbstractCommand
9
{
10
    /**
11
     * Migrator instance.
12
     *
13
     * @var Migrator
14
     */
15
    protected $migrator;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param Migrator $migrator
21
     */
22
    public function __construct(Migrator $migrator)
23
    {
24
        $this->migrator = $migrator;
25
26
        parent::__construct();
27
    }
28
29
    /**
30
     * Configures the current command.
31
     */
32
    protected function configure()
33
    {
34
        $this->setName('archive')
35
            ->setDescription('Move migration into archive')
36
            ->addOption('without', 'w', InputOption::VALUE_REQUIRED, 'Archive without last N migration');
37
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @return null|int
43
     */
44
    protected function fire()
45
    {
46
        $files = $this->migrator->getAllMigrations();
47
        $without = $this->input->getOption('without') ?: 0;
48
        if ($without > 0) {
49
            $files = array_slice($files, 0, $without * -1);
50
        }
51
52
        $count = $this->migrator->moveMigrationFiles($files);
53
54
        if ($count) {
55
            $this->message("<info>Moved to archive:</info> {$count}");
56
        } else {
57
            $this->info('Nothing to move');
58
        }
59
    }
60
}
61