Issues (45)

src/migrations/Install.php (1 issue)

Severity
1
<?php
2
/**
3
 * Socializer plugin for Craft CMS 3.x
4
 *
5
 * @link      https://enupal.com/
6
 * @copyright Copyright (c) 2019 Enupal LLC
7
 */
8
9
namespace enupal\socializer\migrations;
10
11
use craft\db\Migration;
12
13
/**
14
 * Installation Migration
15
 */
16
class Install extends Migration
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function safeUp()
22
    {
23
        $this->createTables();
24
        $this->addIndexes();
25
        $this->addForeignKeys();
26
27
        return true;
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function safeDown()
34
    {
35
        $this->dropTableIfExists('{{%enupalsocializer_tokens}}');
36
        $this->dropTableIfExists('{{%enupalsocializer_providers}}');
37
38
        return true;
39
    }
40
41
    /**
42
     * Creates the tables.
43
     *
44
     * @return void
45
     */
46
    protected function createTables()
47
    {
48
        $this->createTable('{{%enupalsocializer_providers}}', [
49
            'id' => $this->primaryKey(),
50
            'name' => $this->string()->notNull(),
51
            'handle' => $this->string()->notNull(),
52
            'type' => $this->string()->notNull(),
53
            'clientId' => $this->string(),
54
            'clientSecret' => $this->string(),
55
            'fieldMapping' => $this->text(),
56
            //
57
            'dateCreated' => $this->dateTime()->notNull(),
58
            'dateUpdated' => $this->dateTime()->notNull(),
59
            'dateDeleted' => $this->dateTime()->null(),
60
            'uid' => $this->uid(),
61
        ]);
62
63
        $this->createTable('{{%enupalsocializer_tokens}}', [
64
            'id' => $this->primaryKey(),
65
            'userId' => $this->integer(),
66
            'providerId' => $this->integer(),
67
            'accessToken' => $this->text(),
68
            //
69
            'dateCreated' => $this->dateTime()->notNull(),
70
            'dateUpdated' => $this->dateTime()->notNull(),
71
            'dateDeleted' => $this->dateTime()->null(),
72
            'uid' => $this->uid(),
73
        ]);
74
    }
75
76
    protected function addIndexes()
77
    {
78
        $this->createIndex(null, '{{%enupalsocializer_tokens}}', 'userId', false);
79
        $this->createIndex(null, '{{%enupalsocializer_tokens}}', 'providerId', false);
80
    }
81
82
    /**
83
     * Adds the foreign keys.
84
     *
85
     * @return void
86
     */
87
    protected function addForeignKeys()
88
    {
89
        $this->addForeignKey(
90
            $this->db->getForeignKeyName(
91
                '{{%enupalsocializer_providers}}', 'id'
0 ignored issues
show
The call to craft\db\Connection::getForeignKeyName() has too many arguments starting with '{{%enupalsocializer_providers}}'. ( Ignorable by Annotation )

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

91
            $this->db->/** @scrutinizer ignore-call */ 
92
                       getForeignKeyName(

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...
92
            ),
93
            '{{%enupalsocializer_providers}}', 'id',
94
            '{{%elements}}', 'id', 'CASCADE', null
95
        );
96
97
        $this->addForeignKey(
98
            $this->db->getForeignKeyName(
99
                '{{%enupalsocializer_tokens}}', 'userId'
100
            ),
101
            '{{%enupalsocializer_tokens}}', 'userId',
102
            '{{%users}}', 'id', 'CASCADE', null
103
        );
104
105
        $this->addForeignKey(
106
            $this->db->getForeignKeyName(
107
                '{{%enupalsocializer_tokens}}', 'providerId'
108
            ),
109
            '{{%enupalsocializer_tokens}}', 'providerId',
110
            '{{%enupalsocializer_providers}}', 'id', 'CASCADE', null
111
        );
112
    }
113
}
114