m000000_000012_term_relationship   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 38
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 24 24 2
A down() 4 4 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
use yii\db\Schema;
4
5
/**
6
 * Class m000000_000012_term_relationship
7
 *
8
 * @author Agiel K. Saputra <[email protected]>
9
 * @since 0.1.0
10
 */
11 View Code Duplication
class m000000_000012_term_relationship extends \yii\db\Migration
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function up()
17
    {
18
        $tableOptions = null;
19
20
        if ($this->db->driverName === 'mysql') {
21
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
22
        }
23
24
        $this->createTable('{{%term_relationship}}', [
25
            'post_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
26
            'term_id' => Schema::TYPE_INTEGER . '(11) NOT NULL',
27
            'PRIMARY KEY ([[post_id]], [[term_id]])',
28
            'FOREIGN KEY ([[post_id]]) REFERENCES {{%post}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE',
29
            'FOREIGN KEY ([[term_id]]) REFERENCES {{%term}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE',
30
        ], $tableOptions);
31
32
        /**
33
         * First post has post-category and post-tag
34
         */
35
        $this->batchInsert('{{%term_relationship}}', ['post_id', 'term_id'], [
36
            [1, 1],
37
            [1, 2],
38
        ]);
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function down()
45
    {
46
        $this->dropTable('{{%term_relationship}}');
47
    }
48
}
49