Passed
Push — master ( 6c23c3...c1688f )
by Julito
09:45
created

Version20191206150000::up()   D

Complexity

Conditions 10
Paths 512

Size

Total Lines 52
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 33
nc 512
nop 1
dl 0
loc 52
rs 4.1777
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20191206150000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Extra field changes';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $table = $schema->getTable('extra_field');
22
        if (false === $table->hasColumn('helper_text')) {
23
            $this->addSql('ALTER TABLE extra_field ADD helper_text text DEFAULT NULL AFTER display_text');
24
        }
25
        $this->addSql('ALTER TABLE extra_field_values CHANGE value value LONGTEXT DEFAULT NULL;');
26
        if (false === $table->hasColumn('description')) {
27
            $this->addSql('ALTER TABLE extra_field ADD description LONGTEXT DEFAULT NULL');
28
        }
29
30
        $table = $schema->getTable('extra_field_values');
31
        if (!$table->hasIndex('idx_efv_item')) {
32
            $this->addSql('CREATE INDEX idx_efv_item ON extra_field_values (item_id)');
33
        }
34
35
        $table = $schema->getTable('extra_field_option_rel_field_option');
36
        if (!$table->hasForeignKey('FK_8E04DF6B42C79BE5')) {
37
            $this->addSql('ALTER TABLE extra_field_option_rel_field_option ADD CONSTRAINT FK_8E04DF6B42C79BE5 FOREIGN KEY (field_option_id) REFERENCES extra_field_options (id);');
38
            $this->addSql('CREATE INDEX IDX_8E04DF6B42C79BE5 ON extra_field_option_rel_field_option (field_option_id)');
39
        }
40
        if (!$table->hasForeignKey('FK_8E04DF6BCFAFCECC')) {
41
            $this->addSql('ALTER TABLE extra_field_option_rel_field_option ADD CONSTRAINT FK_8E04DF6BCFAFCECC FOREIGN KEY (related_field_option_id) REFERENCES extra_field_options (id);');
42
            $this->addSql('CREATE INDEX IDX_8E04DF6BCFAFCECC ON extra_field_option_rel_field_option (related_field_option_id);');
43
        }
44
        if (!$table->hasForeignKey('FK_8E04DF6B443707B0')) {
45
            $this->addSql('ALTER TABLE extra_field_option_rel_field_option ADD CONSTRAINT FK_8E04DF6B443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id);');
46
            $this->addSql('CREATE INDEX IDX_8E04DF6B443707B0 ON extra_field_option_rel_field_option (field_id);');
47
        }
48
49
        $table = $schema->getTable('extra_field_rel_tag');
50
51
        $this->addSql('ALTER TABLE extra_field_rel_tag CHANGE field_id field_id INT DEFAULT NULL');
52
        $this->addSql('ALTER TABLE extra_field_rel_tag CHANGE tag_id tag_id INT DEFAULT NULL');
53
54
        if (!$table->hasForeignKey('FK_F8817295443707B0')) {
55
            $this->addSql('ALTER TABLE extra_field_rel_tag ADD CONSTRAINT FK_F8817295443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id) ON DELETE CASCADE');
56
        }
57
58
        if (!$table->hasForeignKey('FK_F8817295BAD26311')) {
59
            $this->addSql(
60
                'ALTER TABLE extra_field_rel_tag ADD CONSTRAINT FK_F8817295BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE'
61
            );
62
        }
63
64
        $table = $schema->getTable('tag');
65
        $this->addSql('ALTER TABLE tag CHANGE field_id field_id INT DEFAULT NULL');
66
        if (!$table->hasForeignKey('FK_389B783443707B0')) {
67
            $this->addSql(
68
                'ALTER TABLE tag ADD CONSTRAINT FK_389B783443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id) ON DELETE CASCADE'
69
            );
70
            $this->addSql('CREATE INDEX IDX_389B783443707B0 ON tag (field_id)');
71
        }
72
    }
73
}
74