CreateSubscriptionsTable::change()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 53
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 43
nc 2
nop 0
dl 0
loc 53
rs 9.232
c 1
b 0
f 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 CreateSubscriptionsTable 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::subscriptions()->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('id_token', 'biginteger')
34
            ->addColumn('id_last_transaction', 'biginteger')
35
            ->addColumn('customer_id', 'biginteger')
36
            ->addColumn('customer_type', 'string')
37
            ->addColumn('status', 'enum', ['values' => ['not_started', 'active', 'completed', 'canceled']])
38
            ->addColumn('billing_period', 'enum', ['values' => ['daily', 'weekly', 'monthly', 'yearly']])
39
            ->addColumn('billing_interval', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY])
0 ignored issues
show
Bug introduced by
The type Phinx\Db\Adapter\MysqlAdapter 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...
40
            ->addColumn(
41
                'billing_count',
42
                'integer',
43
                ['null' => true, 'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]
44
            )
45
            ->addColumn('start_at', 'date', ['null' => true])
46
            ->addColumn('cancel_at', 'date', ['null' => true])
47
            ->addColumn('ended_at', 'date', ['null' => true])
48
            ->addColumn('charge_at', 'date', ['null' => true])
49
            ->addColumn('charge_attempts', 'integer', ['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY])
50
            ->addColumn(
51
                'charge_count',
52
                'integer',
53
                ['null' => true, 'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]
54
            )
55
            ->addColumn('charge_method', 'string')
56
            ->addColumn('metadata', 'json', ['null' => true])
57
            ->addColumn('modified', 'timestamp', [
58
                'default' => 'CURRENT_TIMESTAMP',
59
                'update' => 'CURRENT_TIMESTAMP',
60
            ])
61
            ->addColumn('created', 'timestamp', [
62
                'default' => 'CURRENT_TIMESTAMP',
63
            ]);
64
65
        $table->addIndex(['id_method']);
66
        $table->addIndex(['id_token']);
67
        $table->addIndex(['id_last_transaction']);
68
        $table->addIndex(['customer_id', 'customer_type']);
69
        $table->addIndex(['status']);
70
        $table->addIndex(['start_at']);
71
        $table->addIndex(['cancel_at']);
72
        $table->addIndex(['ended_at']);
73
        $table->addIndex(['charge_at']);
74
75
        $table->save();
76
    }
77
}
78