Version3203Date20211226193332::changeSchema()   F
last analyzed

Complexity

Conditions 11
Paths 513

Size

Total Lines 97
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 66
c 1
b 0
f 0
nc 513
nop 3
dl 0
loc 97
rs 3.8029

How to fix   Long Method    Complexity   

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
namespace OCA\audioplayer\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
/**
13
 * Auto-generated migration step: Please modify to your needs!
14
 */
15
class Version3203Date20211226193332 extends SimpleMigrationStep {
16
17
    /**
18
     * @param IOutput $output
19
     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
     * @param array $options
21
     */
22
    public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
23
    }
24
25
    /**
26
     * @param IOutput $output
27
     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28
     * @param array $options
29
     * @return null|ISchemaWrapper
30
     */
31
    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
32
        /** @var ISchemaWrapper $schema */
33
        $schema = $schemaClosure();
34
35
        if (!$schema->hasTable('audioplayer_albums')) {
36
            $table = $schema->createTable('audioplayer_albums');
37
            $table->addColumn('id', 'integer', [
38
                'autoincrement' => true,
39
                'notnull' => true,
40
                'unsigned' => true,
41
            ]);
42
            $table->addColumn('user_id', 'string', [
43
                'notnull' => true,
44
                'length' => 64,
45
            ]);
46
            $table->addColumn('name', 'string', [
47
                'notnull' => false,
48
                'length' => 256,
49
            ]);
50
            $table->addColumn('year', 'integer', [
51
                'notnull' => false,
52
                'unsigned' => true,
53
            ]);
54
            $table->addColumn('genre_id', 'integer', [
55
                'notnull' => false,
56
            ]);
57
            $table->addColumn('cover', 'text', [
58
                'notnull' => false,
59
            ]);
60
            $table->addColumn('bgcolor', 'string', [
61
                'notnull' => false,
62
                'length' => 40,
63
            ]);
64
            $table->addColumn('artist_id', 'integer', [
65
                'notnull' => false,
66
            ]);
67
            $table->addColumn('folder_id', 'integer', [
68
                'notnull' => false,
69
            ]);
70
            $table->setPrimaryKey(['id']);
71
            $table->addIndex(['user_id'], 'albums_user_id_idx');
72
            $table->addIndex(['id', 'user_id'], 'albums_album_user_idx');
73
        } else {
74
            $table = $schema->getTable('audioplayer_albums');
75
            if (!$table->hasColumn('id')) {
76
                $table->addColumn('id', 'integer', [
77
                    'autoincrement' => true,
78
                    'notnull' => true,
79
                    'unsigned' => true,
80
                ]);
81
            }
82
            if (!$table->hasColumn('user_id')) {
83
                $table->addColumn('user_id', 'string', [
84
                    'notnull' => true,
85
                    'length' => 64,
86
                ]);
87
            }
88
            if (!$table->hasColumn('name')) {
89
                $table->addColumn('name', 'string', [
90
                    'notnull' => false,
91
                    'length' => 256,
92
                ]);
93
            }
94
            if (!$table->hasColumn('year')) {
95
                $table->addColumn('year', 'integer', [
96
                    'notnull' => false,
97
                    'unsigned' => true,
98
                ]);
99
            }
100
            if (!$table->hasColumn('genre_id')) {
101
                $table->addColumn('genre_id', 'integer', [
102
                    'notnull' => false,
103
                ]);
104
            }
105
            if (!$table->hasColumn('cover')) {
106
                $table->addColumn('cover', 'text', [
107
                    'notnull' => false,
108
                ]);
109
            }
110
            if (!$table->hasColumn('bgcolor')) {
111
                $table->addColumn('bgcolor', 'string', [
112
                    'notnull' => false,
113
                    'length' => 40,
114
                ]);
115
            }
116
            if (!$table->hasColumn('artist_id')) {
117
                $table->addColumn('artist_id', 'integer', [
118
                    'notnull' => false,
119
                ]);
120
            }
121
            if (!$table->hasColumn('folder_id')) {
122
                $table->addColumn('folder_id', 'integer', [
123
                    'notnull' => false,
124
                ]);
125
            }
126
        }
127
        return $schema;
128
    }
129
130
    /**
131
     * @param IOutput $output
132
     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
133
     * @param array $options
134
     */
135
    public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
136
    }
137
}