MigrationsGenerateDoctrineCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
B generateMigration() 0 28 1
1
<?php
2
3
namespace Rey\BitrixMigrations\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Doctrine\DBAL\Migrations\Configuration\Configuration;
8
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
9
10
class MigrationsGenerateDoctrineCommand extends GenerateCommand
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected function configure()
16
    {
17
        parent::configure();
18
        $this->setName('bitrix:' . $this->getName());
19
    }
20
21
    /**
22
     * @param Doctrine\DBAL\Migrations\Configuration\Configuration $configuration
23
     * @param \Symfony\Component\Console\Input\InputInterface $input
24
     * @param string $version
25
     * @param string|null $up
26
     * @param string|null $down
27
     *
28
     * @return string
29
     */
30
    protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null)
31
    {
32
        $abstractMigrationClass = $configuration->getMigrationsAbstractClass();
0 ignored issues
show
Bug introduced by
The method getMigrationsAbstractClass() does not exist on Doctrine\DBAL\Migrations...iguration\Configuration. Did you maybe mean getMigrations()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
33
        $example = "// \$this->enableBitrixAPI(); //include and configuration Bitrix API\n";
34
35
        $up = $example . $up;
36
        $down = $example . $down;
37
        $path = parent::generateMigration($configuration, $input, $version, $up, $down);
38
39
        $migrationContent = file_get_contents($path);
40
41
        $migrationContent = str_replace(
42
            'Doctrine\DBAL\Migrations\AbstractMigration',
43
            $abstractMigrationClass.' as AbstractMigration',
44
            $migrationContent
45
        );
46
47
        $migrationContent = str_replace(
48
            'use '.$abstractMigrationClass,
49
            'use CModule, CMain, CIBlock, CForm;// etc. Bitrix api classes' . "\n"
50
            . 'use '.$abstractMigrationClass,
51
            $migrationContent
52
        );
53
54
        file_put_contents($path, $migrationContent);
55
56
        return $path;
57
    }
58
}
59