| Conditions | 4 |
| Paths | 8 |
| Total Lines | 176 |
| Code Lines | 125 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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('music_podcast_channels')) { |
||
| 36 | $table = $schema->createTable('music_podcast_channels'); |
||
| 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('rss_url', 'string', [ |
||
| 47 | 'notnull' => true, |
||
| 48 | 'length' => 2048, |
||
| 49 | ]); |
||
| 50 | $table->addColumn('rss_hash', 'string', [ |
||
| 51 | 'notnull' => true, |
||
| 52 | 'length' => 64, |
||
| 53 | ]); |
||
| 54 | $table->addColumn('content_hash', 'string', [ |
||
| 55 | 'notnull' => true, |
||
| 56 | 'length' => 64, |
||
| 57 | ]); |
||
| 58 | $table->addColumn('update_checked', 'datetime', [ |
||
| 59 | 'notnull' => true, |
||
| 60 | ]); |
||
| 61 | $table->addColumn('published', 'datetime', [ |
||
| 62 | 'notnull' => false, |
||
| 63 | ]); |
||
| 64 | $table->addColumn('last_build_date', 'datetime', [ |
||
| 65 | 'notnull' => false, |
||
| 66 | ]); |
||
| 67 | $table->addColumn('title', 'string', [ |
||
| 68 | 'notnull' => false, |
||
| 69 | 'length' => 256, |
||
| 70 | ]); |
||
| 71 | $table->addColumn('link_url', 'string', [ |
||
| 72 | 'notnull' => false, |
||
| 73 | 'length' => 2048, |
||
| 74 | ]); |
||
| 75 | $table->addColumn('language', 'string', [ |
||
| 76 | 'notnull' => false, |
||
| 77 | 'length' => 32, |
||
| 78 | ]); |
||
| 79 | $table->addColumn('copyright', 'string', [ |
||
| 80 | 'notnull' => false, |
||
| 81 | 'length' => 256, |
||
| 82 | ]); |
||
| 83 | $table->addColumn('author', 'string', [ |
||
| 84 | 'notnull' => false, |
||
| 85 | 'length' => 256, |
||
| 86 | ]); |
||
| 87 | $table->addColumn('description', 'text', [ |
||
| 88 | 'notnull' => false, |
||
| 89 | ]); |
||
| 90 | $table->addColumn('image_url', 'string', [ |
||
| 91 | 'notnull' => false, |
||
| 92 | 'length' => 2048, |
||
| 93 | ]); |
||
| 94 | $table->addColumn('category', 'string', [ |
||
| 95 | 'notnull' => false, |
||
| 96 | 'length' => 256, |
||
| 97 | ]); |
||
| 98 | $table->addColumn('starred', 'datetime', [ |
||
| 99 | 'notnull' => false, |
||
| 100 | ]); |
||
| 101 | $table->addColumn('created', 'datetime', [ |
||
| 102 | 'notnull' => false, |
||
| 103 | ]); |
||
| 104 | $table->addColumn('updated', 'datetime', [ |
||
| 105 | 'notnull' => false, |
||
| 106 | ]); |
||
| 107 | $table->setPrimaryKey(['id']); |
||
| 108 | $table->addUniqueIndex(['rss_hash', 'user_id'], 'music_podcast_channels_index'); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (!$schema->hasTable('music_podcast_episodes')) { |
||
| 112 | $table = $schema->createTable('music_podcast_episodes'); |
||
| 113 | $table->addColumn('id', 'integer', [ |
||
| 114 | 'autoincrement' => true, |
||
| 115 | 'notnull' => true, |
||
| 116 | 'unsigned' => true, |
||
| 117 | ]); |
||
| 118 | $table->addColumn('user_id', 'string', [ |
||
| 119 | 'notnull' => true, |
||
| 120 | 'length' => 64, |
||
| 121 | ]); |
||
| 122 | $table->addColumn('channel_id', 'integer', [ |
||
| 123 | 'notnull' => true, |
||
| 124 | 'unsigned' => true, |
||
| 125 | ]); |
||
| 126 | $table->addColumn('stream_url', 'string', [ |
||
| 127 | 'notnull' => false, |
||
| 128 | 'length' => 2048, |
||
| 129 | ]); |
||
| 130 | $table->addColumn('mimetype', 'string', [ |
||
| 131 | 'notnull' => false, |
||
| 132 | 'length' => 256, |
||
| 133 | ]); |
||
| 134 | $table->addColumn('size', 'integer', [ |
||
| 135 | 'notnull' => false, |
||
| 136 | ]); |
||
| 137 | $table->addColumn('duration', 'integer', [ |
||
| 138 | 'notnull' => false, |
||
| 139 | ]); |
||
| 140 | $table->addColumn('guid', 'string', [ |
||
| 141 | 'notnull' => true, |
||
| 142 | 'length' => 2048, |
||
| 143 | ]); |
||
| 144 | $table->addColumn('guid_hash', 'string', [ |
||
| 145 | 'notnull' => true, |
||
| 146 | 'length' => 64, |
||
| 147 | ]); |
||
| 148 | $table->addColumn('title', 'string', [ |
||
| 149 | 'notnull' => false, |
||
| 150 | 'length' => 256, |
||
| 151 | ]); |
||
| 152 | $table->addColumn('episode', 'integer', [ |
||
| 153 | 'notnull' => false, |
||
| 154 | ]); |
||
| 155 | $table->addColumn('season', 'integer', [ |
||
| 156 | 'notnull' => false, |
||
| 157 | ]); |
||
| 158 | $table->addColumn('link_url', 'string', [ |
||
| 159 | 'notnull' => false, |
||
| 160 | 'length' => 2048, |
||
| 161 | ]); |
||
| 162 | $table->addColumn('published', 'datetime', [ |
||
| 163 | 'notnull' => false, |
||
| 164 | ]); |
||
| 165 | $table->addColumn('keywords', 'string', [ |
||
| 166 | 'notnull' => false, |
||
| 167 | 'length' => 256, |
||
| 168 | ]); |
||
| 169 | $table->addColumn('copyright', 'string', [ |
||
| 170 | 'notnull' => false, |
||
| 171 | 'length' => 256, |
||
| 172 | ]); |
||
| 173 | $table->addColumn('author', 'string', [ |
||
| 174 | 'notnull' => false, |
||
| 175 | 'length' => 256, |
||
| 176 | ]); |
||
| 177 | $table->addColumn('description', 'text', [ |
||
| 178 | 'notnull' => false, |
||
| 179 | ]); |
||
| 180 | $table->addColumn('starred', 'datetime', [ |
||
| 181 | 'notnull' => false, |
||
| 182 | ]); |
||
| 183 | $table->addColumn('created', 'datetime', [ |
||
| 184 | 'notnull' => false, |
||
| 185 | ]); |
||
| 186 | $table->addColumn('updated', 'datetime', [ |
||
| 187 | 'notnull' => false, |
||
| 188 | ]); |
||
| 189 | $table->setPrimaryKey(['id']); |
||
| 190 | $table->addUniqueIndex(['guid_hash', 'channel_id', 'user_id'], 'music_podcast_episodes_index'); |
||
| 191 | } |
||
| 192 | |||
| 193 | $table = $schema->getTable('music_bookmarks'); |
||
| 194 | if (!$table->hasColumn('type')) { |
||
| 195 | $table->addColumn('type', 'integer', [ |
||
| 196 | 'notnull' => true, |
||
| 197 | ]); |
||
| 198 | $table->dropIndex('music_bookmarks_user_track'); |
||
| 199 | $table->dropColumn('track_id'); |
||
| 200 | $table->addColumn('entry_id', 'integer', [ |
||
| 201 | 'notnull' => true, |
||
| 202 | ]); |
||
| 203 | $table->addUniqueIndex(['user_id', 'type', 'entry_id'], 'music_bookmarks_index'); |
||
| 204 | } |
||
| 205 | |||
| 206 | return $schema; |
||
| 207 | } |
||
| 217 |