Conditions | 6 |
Paths | 6 |
Total Lines | 65 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
40 | public function handle() |
||
41 | { |
||
42 | $expenses = Expense::where('due_date','=',Carbon::today()->format('Y-m-d'))->get(); |
||
43 | |||
44 | foreach($expenses as $expense) |
||
45 | { |
||
46 | if ($expense->repeat == 1) |
||
47 | { |
||
48 | $expenseData = array('name' => $expense->name, |
||
49 | 'category_id' => $expense->category_id, |
||
50 | 'due_date' => $expense->due_date->addDays(1), |
||
51 | 'repeat' => $expense->repeat, |
||
52 | 'note' => $expense->note, |
||
53 | 'amount' => $expense->amount, |
||
54 | 'paid' => 0, |
||
55 | 'created_by' => 1, |
||
56 | 'updated_by' => 1); |
||
57 | |||
58 | $newExpense = new Expense($expenseData); |
||
59 | $newExpense->save(); |
||
60 | } |
||
61 | elseif ($expense->repeat == 2) |
||
62 | { |
||
63 | $expenseData = array('name' => $expense->name, |
||
64 | 'category_id' => $expense->category_id, |
||
65 | 'due_date' => $expense->due_date->addWeek(), |
||
66 | 'repeat' => $expense->repeat, |
||
67 | 'note' => $expense->note, |
||
68 | 'amount' => $expense->amount, |
||
69 | 'paid' => 0, |
||
70 | 'created_by' => 1, |
||
71 | 'updated_by' => 1); |
||
72 | |||
73 | $newExpense = new Expense($expenseData); |
||
74 | $newExpense->save(); |
||
75 | } |
||
76 | elseif ($expense->repeat == 3) |
||
77 | { |
||
78 | $expenseData = array('name' => $expense->name, |
||
79 | 'category_id' => $expense->category_id, |
||
80 | 'due_date' => $expense->due_date->addMonth(), |
||
81 | 'repeat' => $expense->repeat, |
||
82 | 'note' => $expense->note, |
||
83 | 'amount' => $expense->amount, |
||
84 | 'paid' => 0, |
||
85 | 'created_by' => 1, |
||
86 | 'updated_by' => 1); |
||
87 | |||
88 | $newExpense = new Expense($expenseData); |
||
89 | $newExpense->save(); |
||
90 | } |
||
91 | elseif ($expense->repeat == 4) |
||
92 | { |
||
93 | $expenseData = array('name' => $expense->name, |
||
94 | 'category_id' => $expense->category_id, |
||
95 | 'due_date' => $expense->due_date->addYear(), |
||
96 | 'repeat' => $expense->repeat, |
||
97 | 'note' => $expense->note, |
||
98 | 'amount' => $expense->amount, |
||
99 | 'paid' => 0, |
||
100 | 'created_by' => 1, |
||
101 | 'updated_by' => 1); |
||
102 | |||
103 | $newExpense = new Expense($expenseData); |
||
104 | $newExpense->save(); |
||
105 | } |
||
110 |