Completed
Push — master ( c9b1f2...7edc4b )
by Gino
02:53 queued 01:13
created

DropDeprecatedPostTagTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 29.03 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 9
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 4 1
A down() 9 17 2

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
namespace GinoPane\BlogTaxonomy\Updates;
4
5
use Schema;
6
use GinoPane\BlogTaxonomy\Models\Tag;
7
use October\Rain\Database\Updates\Migration;
8
9
/**
10
 * Class DropDeprecatedPostTagTable
11
 *
12
 * @package GinoPane\BlogTaxonomy\Updates
13
 */
14
class DropDeprecatedPostTagTable extends Migration
15
{
16
    /**
17
     * Execute migrations
18
     */
19
    public function up()
20
    {
21
        Schema::dropIfExists('ginopane_blogtaxonomy_post_tag');
22
    }
23
24
    /**
25
     * Rollback migrations
26
     */
27
    public function down()
28
    {
29
        if (!Schema::hasTable('ginopane_blogtaxonomy_post_tag')) {
30
            Schema::create(
31
                'ginopane_blogtaxonomy_post_tag',
32 View Code Duplication
                static function ($table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
                    $table->engine = 'InnoDB';
34
35
                    $table->integer('tag_id')->unsigned()->nullable()->default(null);
36
                    $table->integer('post_id')->unsigned()->nullable()->default(null);
37
                    $table->index(['tag_id', 'post_id']);
38
                    $table->foreign('tag_id')->references('id')->on(Tag::TABLE_NAME)->onDelete('cascade');
39
                    $table->foreign('post_id')->references('id')->on('rainlab_blog_posts')->onDelete('cascade');
40
                }
41
            );
42
        }
43
    }
44
}
45