| Conditions | 1 |
| Paths | 1 |
| Total Lines | 66 |
| Code Lines | 38 |
| 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 |
||
| 13 | public function run() |
||
| 14 | { |
||
| 15 | DB::table($this->table)->truncate(); |
||
| 16 | DB::table($this->table)->insert([ |
||
| 17 | // Choices for question 1 |
||
| 18 | [ |
||
| 19 | 'question_id' => 1, |
||
| 20 | 'is_right_choice' => '0', |
||
| 21 | 'choice' => 'A pineapple tree with cucumbers' |
||
| 22 | ], |
||
| 23 | [ |
||
| 24 | 'question_id' => 1, |
||
| 25 | 'is_right_choice' => '1', // this is the right choice (enum = 1 = true, enum = 0 = false) |
||
| 26 | 'choice' => 'A binary search tree' |
||
| 27 | ], |
||
| 28 | [ |
||
| 29 | 'question_id' => 1, |
||
| 30 | 'is_right_choice' => '0', |
||
| 31 | 'choice' => 'A church choir' |
||
| 32 | ], |
||
| 33 | [ |
||
| 34 | 'question_id' => 1, |
||
| 35 | 'is_right_choice' => '0', |
||
| 36 | 'choice' => 'A logarithmic skip line' |
||
| 37 | ], |
||
| 38 | // Choices for question 2 |
||
| 39 | [ |
||
| 40 | 'question_id' => 2, |
||
| 41 | 'is_right_choice' => '0', |
||
| 42 | 'choice' => '{A, B, C, D, E, F, G}' |
||
| 43 | ], |
||
| 44 | [ |
||
| 45 | 'question_id' => 2, |
||
| 46 | 'is_right_choice' => '0', |
||
| 47 | 'choice' => '{{1, 0.5, 18, 2.2, 1.8, 89, 45}, 2, 4, 8}' |
||
| 48 | ], |
||
| 49 | [ |
||
| 50 | 'question_id' => 2, |
||
| 51 | 'is_right_choice' => '0', |
||
| 52 | 'choice' => '{-1, -2, -3, {-8, -12, -89}, 2, 1}' |
||
| 53 | ], |
||
| 54 | [ |
||
| 55 | 'question_id' => 2, |
||
| 56 | 'is_right_choice' => '1', // this is the right answer again (hi) |
||
| 57 | 'choice' => '{1, 34, 56, {50, 67, 123, 978}, 54, 12, 17}' |
||
| 58 | ], |
||
| 59 | // Choices for question 3 |
||
| 60 | [ |
||
| 61 | 'question_id' => 3, |
||
| 62 | 'is_right_choice' => '1', // this is also right answer...last time |
||
| 63 | 'choice' => 'Violet' |
||
| 64 | ], |
||
| 65 | [ |
||
| 66 | 'question_id' => 3, |
||
| 67 | 'is_right_choice' => '0', |
||
| 68 | 'choice' => 'Cheeky Cherry' |
||
| 69 | ], |
||
| 70 | [ |
||
| 71 | 'question_id' => 3, |
||
| 72 | 'is_right_choice' => '0', |
||
| 73 | 'choice' => 'Racing Green' |
||
| 74 | ], |
||
| 75 | [ |
||
| 76 | 'question_id' => 3, |
||
| 77 | 'is_right_choice' => '0', |
||
| 78 | 'choice' => 'Saucy Strawberry' |
||
| 79 | ] |
||
| 83 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.