CreateTokensTable::change()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 21
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 29
rs 9.584
1
<?php
2
3
declare(strict_types=1);
4
5
use Phinx\Migration\AbstractMigration;
0 ignored issues
show
Bug introduced by
The type Phinx\Migration\AbstractMigration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * Class CreateTokensTable
9
 */
10
final class CreateTokensTable extends AbstractMigration
11
{
12
    /**
13
     * Change Method.
14
     *
15
     * Write your reversible migrations using this method.
16
     *
17
     * More information on writing migrations is available here:
18
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
19
     *
20
     * Remember to call "create()" or "update()" and NOT "save()" when working
21
     * with the Table class.
22
     */
23
    public function change(): void
24
    {
25
        $table_name = \ByTIC\Payments\Utility\PaymentsModels::tokens()->getTable();
26
        $exists = $this->hasTable($table_name);
27
        if ($exists) {
28
            return;
29
        }
30
31
        $table = $this->table($table_name)
32
            ->addColumn('id_method', 'biginteger')
33
            ->addColumn('gateway', 'string')
34
            ->addColumn('customer_id', 'biginteger')
35
            ->addColumn('customer_type', 'string')
36
            ->addColumn('token_id', 'string')
37
            ->addColumn('expiration', 'timestamp')
38
            ->addColumn('modified', 'timestamp', [
39
                'default' => 'CURRENT_TIMESTAMP',
40
                'update' => 'CURRENT_TIMESTAMP',
41
            ])
42
            ->addColumn('created', 'timestamp', [
43
                'default' => 'CURRENT_TIMESTAMP',
44
            ]);
45
46
        $table->addIndex(['id_method']);
47
        $table->addIndex(['gateway']);
48
        $table->addIndex(['token_id']);
49
        $table->addIndex(['id_method', 'token_id'], ['unique' => true]);
50
51
        $table->save();
52
    }
53
}
54