m170613_000001_views::safeDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace dukt\analytics\migrations;
4
5
use craft\db\Migration;
6
7
/**
8
 * The class name is the UTC timestamp in the format of mYYMMDD_HHMMSS_pluginHandle_migrationName
9
 */
10
class m170613_000001_views extends Migration
11
{
12
    /**
13
     * Any migration code in here is wrapped inside of a transaction.
14
     *
15
     * @return bool
16
     */
17
    public function safeUp()
18
    {
19
        $this->createTable(
20
            '{{%analytics_views}}',
21
            [
22
                'id' => $this->primaryKey(),
23
                'name' => $this->string()->notNull(),
24
                'gaAccountId' => $this->string()->notNull(),
25
                'gaAccountName' => $this->string()->notNull(),
26
                'gaPropertyId' => $this->string()->notNull(),
27
                'gaPropertyName' => $this->string()->notNull(),
28
                'gaViewId' => $this->string()->notNull(),
29
                'gaViewName' => $this->string()->notNull(),
30
                'gaViewCurrency' => $this->string()->notNull(),
31
32
                'dateCreated' => $this->dateTime()->notNull(),
33
                'dateUpdated' => $this->dateTime()->notNull(),
34
                'uid' => $this->uid()
35
            ]
36
        );
37
38
        $this->createTable(
39
            '{{%analytics_site_views}}',
40
            [
41
                'id' => $this->primaryKey(),
42
                'siteId' => $this->integer()->notNull(),
43
                'viewId' => $this->integer(),
44
45
                'dateCreated' => $this->dateTime()->notNull(),
46
                'dateUpdated' => $this->dateTime()->notNull(),
47
                'uid' => $this->uid()
48
            ]
49
        );
50
51
        $this->createIndex(null, '{{%analytics_site_views}}', 'siteId,viewId', true);
52
        $this->addForeignKey($this->db->getForeignKeyName('{{%analytics_site_views}}', 'siteId'), '{{%analytics_site_views}}', 'siteId', '{{%sites}}', 'id', 'CASCADE', null);
0 ignored issues
show
Unused Code introduced by
The call to craft\db\Connection::getForeignKeyName() has too many arguments starting with '{{%analytics_site_views}}'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $this->addForeignKey($this->db->/** @scrutinizer ignore-call */ getForeignKeyName('{{%analytics_site_views}}', 'siteId'), '{{%analytics_site_views}}', 'siteId', '{{%sites}}', 'id', 'CASCADE', null);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
53
        $this->addForeignKey($this->db->getForeignKeyName('{{%analytics_site_views}}', 'viewId'), '{{%analytics_site_views}}', 'viewId', '{{%analytics_views}}', 'id', 'CASCADE', null);
54
55
        return true;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function safeDown()
62
    {
63
        echo "m170613_000001_views cannot be reverted.\n";
64
65
        return false;
66
    }
67
}
68