Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 41 |
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 |
||
37 | public function upgrade(): void |
||
38 | { |
||
39 | // These tables were created by webtrees 1.x, and may not exist if we first installed webtrees 2.x |
||
40 | DB::schema()->dropIfExists('site_access_rule'); |
||
41 | DB::schema()->dropIfExists('next_id'); |
||
42 | |||
43 | // Split the media table into media/media_file so that we can store multiple media |
||
44 | // files in each media object. |
||
45 | DB::schema()->create('media_file', static function (Blueprint $table): void { |
||
46 | $table->integer('id', true); |
||
47 | $table->string('m_id', 20); |
||
48 | $table->integer('m_file'); |
||
49 | $table->string('multimedia_file_refn', 248); // GEDCOM only allows 30 characters |
||
50 | $table->string('multimedia_format', 4); |
||
51 | $table->string('source_media_type', 15); |
||
52 | $table->string('descriptive_title', 248); |
||
53 | |||
54 | $table->index(['m_id', 'm_file']); |
||
55 | $table->index(['m_file', 'm_id']); |
||
56 | $table->index(['m_file', 'multimedia_file_refn']); |
||
57 | $table->index(['m_file', 'multimedia_format']); |
||
58 | $table->index(['m_file', 'source_media_type']); |
||
59 | $table->index(['m_file', 'descriptive_title']); |
||
60 | }); |
||
61 | |||
62 | if (DB::schema()->hasColumn('media', 'm_filename')) { |
||
63 | (new Builder(DB::connection()))->from('media_file')->insertUsing([ |
||
64 | 'm_id', |
||
65 | 'm_file', |
||
66 | 'multimedia_file_refn', |
||
67 | 'multimedia_format', |
||
68 | 'source_media_type', |
||
69 | 'descriptive_title', |
||
70 | ], function (Builder $query): void { |
||
71 | $query->select([ |
||
72 | 'm_id', |
||
73 | 'm_file', |
||
74 | $this->substring('m_filename', 1, 248), |
||
75 | $this->substring('m_ext', 1, 4), |
||
76 | $this->substring('m_type', 1, 15), |
||
77 | $this->substring('m_titl', 1, 248), |
||
78 | ])->from('media'); |
||
79 | }); |
||
80 | |||
81 | // SQLite can only drop one column at a time. |
||
82 | DB::schema()->table('media', static function (Blueprint $table): void { |
||
83 | $table->dropColumn('m_filename'); |
||
84 | }); |
||
85 | DB::schema()->table('media', static function (Blueprint $table): void { |
||
86 | $table->dropColumn('m_ext'); |
||
87 | }); |
||
88 | DB::schema()->table('media', static function (Blueprint $table): void { |
||
89 | $table->dropColumn('m_type'); |
||
90 | }); |
||
91 | DB::schema()->table('media', static function (Blueprint $table): void { |
||
92 | $table->dropColumn('m_titl'); |
||
93 | }); |
||
115 |