CreateTransactionsTable::change()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 36
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 28
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 36
rs 9.472
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 CreateTransactionsTable
9
 */
10
final class CreateTransactionsTable 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::transactions()->getTable();
26
        $exists = $this->hasTable($table_name);
27
        if ($exists) {
28
            return;
29
        }
30
31
        $table = $this->table($table_name)
32
            ->addColumn('id_purchase', 'biginteger')
33
            ->addColumn('id_token', 'biginteger', ['null' => true])
34
            ->addColumn('id_subscription', 'biginteger', ['null' => true])
35
            ->addColumn('gateway', 'string')
36
            ->addColumn('currency', 'string', ['limit' => '3'])
37
            ->addColumn('status', 'enum', ['values' => ['pending', 'active', 'error', 'canceled']])
38
            ->addColumn('card', 'string')
39
            ->addColumn('code', 'string')
40
            ->addColumn('reference', 'string')
41
            ->addColumn('metadata', 'json', ['null' => true])
42
            ->addColumn('modified', 'timestamp', [
43
                'default' => 'CURRENT_TIMESTAMP',
44
                'update' => 'CURRENT_TIMESTAMP',
45
            ])
46
            ->addColumn('created', 'timestamp', [
47
                'default' => 'CURRENT_TIMESTAMP',
48
            ]);
49
50
        $table->addIndex(['id_purchase']);
51
        $table->addIndex(['id_token']);
52
        $table->addIndex(['id_subscription']);
53
        $table->addIndex(['currency']);
54
        $table->addIndex(['card']);
55
        $table->addIndex(['code']);
56
        $table->addIndex(['reference']);
57
58
        $table->save();
59
    }
60
}
61