ArchiveCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 0 16 4
A __construct() 0 6 1
A configure() 0 5 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
    protected static $defaultName = 'archive';
17
18
    /**
19
     * Constructor.
20
     *
21
     * @param Migrator    $migrator
22
     * @param string|null $name
23
     */
24
    public function __construct(Migrator $migrator, $name = null)
25
    {
26
        $this->migrator = $migrator;
27
28
        parent::__construct($name);
29
    }
30
31
    /**
32
     * Configures the current command.
33
     */
34
    protected function configure()
35
    {
36
        $this->setDescription('Move migration into archive')
37
            ->addOption('without', 'w', InputOption::VALUE_REQUIRED, 'Archive without last N migration');
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return null|int
44
     */
45
    protected function fire()
46
    {
47
        $files = $this->migrator->getAllMigrations();
48
        $without = $this->input->getOption('without') ?: 0;
49
        if ($without > 0) {
50
            $files = array_slice($files, 0, $without * -1);
51
        }
52
53
        $count = $this->migrator->moveMigrationFiles($files);
54
55
        if ($count) {
56
            $this->message("<info>Moved to archive:</info> {$count}");
57
        } else {
58
            $this->info('Nothing to move');
59
        }
60
    }
61
}
62