Completed
Push — 1.5 ( 846d5e...6d7d0e )
by Paweł
07:53
created

Version20190709090034   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 22 22 1
A down() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Migrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10 View Code Duplication
final class Version20190709090034 extends AbstractMigration
11
{
12
    public function up(Schema $schema): void
13
    {
14
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
15
16
        $this->addSql('DROP INDEX swp_article_slug_idx');
17
        $this->addSql('
18
            CREATE UNIQUE INDEX swp_article_slug_not_null_deleted_at_idx 
19
            ON swp_article (
20
              slug, tenant_code, organization_id, 
21
              deleted_at
22
            ) 
23
            WHERE deleted_at IS NOT NULL
24
        ');
25
26
        $this->addSql('
27
            CREATE UNIQUE INDEX swp_article_slug_null_deleted_at_idx 
28
            ON swp_article (
29
              slug, tenant_code, organization_id
30
            ) 
31
            WHERE deleted_at IS NULL
32
        ');
33
    }
34
35
    public function down(Schema $schema): void
36
    {
37
        $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
38
39
        $this->addSql('DROP INDEX swp_article_slug_not_null_deleted_at_idx');
40
        $this->addSql('DROP INDEX swp_article_slug_null_deleted_at_idx');
41
        $this->addSql('CREATE UNIQUE INDEX swp_article_slug_idx ON swp_article (
42
          slug, tenant_code, organization_id, 
43
          deleted_at
44
        )');
45
    }
46
}
47