Passed
Push — master ( 4c4023...2b0e92 )
by Julito
07:08
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
/**
13
 * Extra fields.
14
 */
15
class Version20191206150000 extends AbstractMigrationChamilo
16
{
17
    public function up(Schema $schema): void
18
    {
19
        $table = $schema->getTable('extra_field');
20
        if (false === $table->hasColumn('helper_text')) {
21
            $this->addSql('ALTER TABLE extra_field ADD helper_text text DEFAULT NULL AFTER display_text');
22
        }
23
        $this->addSql('ALTER TABLE extra_field_values CHANGE value value LONGTEXT DEFAULT NULL;');
24
        if (false === $table->hasColumn('description')) {
25
            $this->addSql('ALTER TABLE extra_field ADD description LONGTEXT DEFAULT NULL');
26
        }
27
28
        $table = $schema->getTable('extra_field_values');
29
        if (!$table->hasIndex('idx_efv_item')) {
30
            $this->addSql('CREATE INDEX idx_efv_item ON extra_field_values (item_id)');
31
        }
32
33
        $table = $schema->getTable('extra_field_option_rel_field_option');
34
        if (!$table->hasForeignKey('FK_8E04DF6B42C79BE5')) {
35
            $this->addSql('ALTER TABLE extra_field_option_rel_field_option ADD CONSTRAINT FK_8E04DF6B42C79BE5 FOREIGN KEY (field_option_id) REFERENCES extra_field_options (id);');
36
            $this->addSql('CREATE INDEX IDX_8E04DF6B42C79BE5 ON extra_field_option_rel_field_option (field_option_id)');
37
        }
38
        if (!$table->hasForeignKey('FK_8E04DF6BCFAFCECC')) {
39
            $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);');
40
            $this->addSql('CREATE INDEX IDX_8E04DF6BCFAFCECC ON extra_field_option_rel_field_option (related_field_option_id);');
41
        }
42
        if (!$table->hasForeignKey('FK_8E04DF6B443707B0')) {
43
            $this->addSql('ALTER TABLE extra_field_option_rel_field_option ADD CONSTRAINT FK_8E04DF6B443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id);');
44
            $this->addSql('CREATE INDEX IDX_8E04DF6B443707B0 ON extra_field_option_rel_field_option (field_id);');
45
        }
46
47
        $table = $schema->getTable('extra_field_rel_tag');
48
49
        $this->addSql('ALTER TABLE extra_field_rel_tag CHANGE field_id field_id INT DEFAULT NULL');
50
        $this->addSql('ALTER TABLE extra_field_rel_tag CHANGE tag_id tag_id INT DEFAULT NULL');
51
52
        if (!$table->hasForeignKey('FK_F8817295443707B0')) {
53
            $this->addSql('ALTER TABLE extra_field_rel_tag ADD CONSTRAINT FK_F8817295443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id) ON DELETE CASCADE');
54
        }
55
56
        if (!$table->hasForeignKey('FK_F8817295BAD26311')) {
57
            $this->addSql(
58
                'ALTER TABLE extra_field_rel_tag ADD CONSTRAINT FK_F8817295BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE'
59
            );
60
        }
61
62
        $table = $schema->getTable('tag');
63
        $this->addSql('ALTER TABLE tag CHANGE field_id field_id INT DEFAULT NULL');
64
        if (!$table->hasForeignKey('FK_389B783443707B0')) {
65
            $this->addSql(
66
                'ALTER TABLE tag ADD CONSTRAINT FK_389B783443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id) ON DELETE CASCADE'
67
            );
68
            $this->addSql('CREATE INDEX IDX_389B783443707B0 ON tag (field_id)');
69
        }
70
    }
71
}
72