Conditions | 11 |
Paths | 513 |
Total Lines | 97 |
Code Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | } |
||
137 | } |