| Conditions | 2 |
| Paths | 2 |
| Total Lines | 70 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 12 | public function safeUp() |
||
| 13 | { |
||
| 14 | $now = time(); |
||
| 15 | $columns = ['id', 'description', 'value', 'rules', 'create_time', 'update_time']; |
||
| 16 | $items = [ |
||
| 17 | [ |
||
| 18 | 'id' => 'upload.image.directory', |
||
| 19 | 'description' => 'Image Directory', |
||
| 20 | 'value' => 'images', |
||
| 21 | 'rules' => [ |
||
| 22 | ['required'], |
||
| 23 | ], |
||
| 24 | ], |
||
| 25 | [ |
||
| 26 | 'id' => 'upload.image.maxSize', |
||
| 27 | 'description' => 'Image Maximum Size(bytes)', |
||
| 28 | 'value' => 1024 * 1024, |
||
| 29 | 'rules' => [ |
||
| 30 | ['required'], |
||
| 31 | ['number'], |
||
| 32 | ], |
||
| 33 | ], |
||
| 34 | [ |
||
| 35 | 'id' => 'upload.image.extensions', |
||
| 36 | 'description' => 'Image Extensions', |
||
| 37 | 'value' => 'gif,jpeg,jpg,png', |
||
| 38 | 'rules' => [ |
||
| 39 | ['required'], |
||
| 40 | ], |
||
| 41 | ], |
||
| 42 | |||
| 43 | [ |
||
| 44 | 'id' => 'upload.video.directory', |
||
| 45 | 'description' => 'Video Directory', |
||
| 46 | 'value' => 'videos', |
||
| 47 | 'rules' => [ |
||
| 48 | ['required'], |
||
| 49 | ], |
||
| 50 | ], |
||
| 51 | [ |
||
| 52 | 'id' => 'upload.video.maxSize', |
||
| 53 | 'description' => 'Video Maximum Size(bytes)', |
||
| 54 | 'value' => 10 * 1024 * 1024, |
||
| 55 | 'rules' => [ |
||
| 56 | ['required'], |
||
| 57 | ['number'], |
||
| 58 | ], |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | 'id' => 'upload.video.extensions', |
||
| 62 | 'description' => 'Video Extensions', |
||
| 63 | 'value' => 'mp4', |
||
| 64 | 'rules' => [ |
||
| 65 | ['required'], |
||
| 66 | ], |
||
| 67 | ], |
||
| 68 | ]; |
||
| 69 | |||
| 70 | $rows = []; |
||
| 71 | foreach ($items as $item) { |
||
| 72 | $rows[] = [ |
||
| 73 | $item['id'], |
||
| 74 | $item['description'], |
||
| 75 | $item['value'], |
||
| 76 | json_encode($item['rules'] ?? []), |
||
| 77 | $now, |
||
| 78 | $now |
||
| 79 | ]; |
||
| 80 | } |
||
| 81 | $this->batchInsert($this->tableName, $columns, $rows); |
||
| 82 | } |
||
| 91 |