MigrationsGenerateDoctrineCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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