Conditions | 21 |
Paths | > 20000 |
Total Lines | 150 |
Code Lines | 106 |
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 |
||
97 | public function migrateExcel() |
||
98 | { |
||
99 | $tax_percent = \Utilities::getSetting('taxes'); |
||
100 | |||
101 | $lines = Excel::load('import.csv')->get(); |
||
102 | |||
103 | DB::beginTransaction(); |
||
104 | |||
105 | try { |
||
106 | foreach ($lines as $line) { |
||
107 | |||
108 | $invoiceCounter = \Utilities::getSetting('invoice_last_number') + 1; |
||
109 | $invoicePrefix = \Utilities::getSetting('invoice_prefix'); |
||
110 | $invoice_number = $invoicePrefix.$invoiceCounter; |
||
111 | |||
112 | $memberCounter = \Utilities::getSetting('member_last_number') + 1; |
||
113 | $memberPrefix = \Utilities::getSetting('member_prefix'); |
||
114 | $member_code = $memberPrefix.$memberCounter; |
||
115 | |||
116 | $dob = Carbon::createFromFormat('d/m/Y', $line->get('dob'))->toDateString(); |
||
117 | $gender = ($line->get('gender') == 'male' ? 'm' : 'f'); |
||
118 | // $explodedName = explode(" ", $line->get('name')); |
||
119 | $email = $member_code . "@evolvegym.in"; |
||
120 | |||
121 | $address = (empty($line->get('address')) ? 'Naigaon east' : $line->get('address')); |
||
122 | |||
123 | $member = Member::create(['name'=> $line->get('name'), |
||
124 | 'DOB'=> $dob, |
||
125 | 'gender'=> $gender, |
||
126 | 'contact'=> $line->get('contact'), |
||
127 | 'emergency_contact'=> $line->get('emergency_contact'), |
||
128 | 'health_issues'=> $line->get('health_issues'), |
||
129 | 'email'=> $email, |
||
130 | 'address'=> $address, |
||
131 | 'proof_name'=> 'none', |
||
132 | 'member_code'=> $member_code, |
||
133 | 'status'=> '1', |
||
134 | 'pin_code'=> 401208, |
||
135 | 'occupation'=> '5', |
||
136 | 'aim'=> '0', |
||
137 | 'source'=> '0', |
||
138 | 'created_by'=> Auth::user()->id, |
||
139 | 'updated_by'=> Auth::user()->id |
||
140 | ]); |
||
141 | |||
142 | $invoice_total = $line->get('total_amount'); |
||
143 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
144 | $pending = empty($line->get('pending_amount')) ? '0' : $line->get('pending_amount'); |
||
145 | $discount = empty($line->get('discount_amount')) ? '0' : $line->get('discount_amount'); |
||
146 | $payment_amount = $invoice_total - (int) $pending; |
||
147 | |||
148 | if ($payment_amount == $invoice_total) { |
||
149 | $paymentStatus = \constPaymentStatus::Paid; |
||
150 | } |
||
151 | elseif($payment_amount > 0 && $payment_amount < $invoice_total) { |
||
152 | $paymentStatus = \constPaymentStatus::Partial; |
||
153 | } |
||
154 | elseif($payment_amount == 0) { |
||
155 | $paymentStatus = \constPaymentStatus::Unpaid; |
||
156 | } |
||
157 | else { |
||
158 | $paymentStatus = \constPaymentStatus::Overpaid; |
||
159 | } |
||
160 | |||
161 | if(empty($line->discount_percent) && !empty($line->discount_amount)) { |
||
162 | $discountPercent = 'custom'; |
||
163 | } |
||
164 | elseif(empty($line->discount_percent) && empty($line->discount_amount)) { |
||
165 | $discountPercent = '0'; |
||
166 | } |
||
167 | elseif(!empty($line->discount_percent)) { |
||
168 | $discountPercent = str_replace("%", "", $line->discount_percent); |
||
169 | } |
||
170 | |||
171 | $invoice = Invoice::create(['invoice_number'=> $invoice_number, |
||
172 | 'member_id'=> $member->id, |
||
173 | 'total'=> $invoice_total, |
||
174 | 'status'=> $paymentStatus, |
||
175 | 'pending_amount'=> $pending, |
||
176 | 'discount_amount'=> $discount, |
||
177 | 'discount_percent'=> $discountPercent, |
||
178 | 'discount_note'=> null, |
||
179 | 'tax'=> ($tax_percent / 100) * $invoice_total, |
||
180 | 'additional_fees'=> '0', |
||
181 | 'note'=> null, |
||
182 | 'created_by'=> Auth::user()->id, |
||
183 | 'updated_by'=> Auth::user()->id |
||
184 | ]); |
||
185 | |||
186 | $start_date = Carbon::createFromFormat('d/m/Y', $line->get('start_date')); |
||
187 | $planId = $line->get('plan'); |
||
188 | |||
189 | if($planId == 3) { |
||
190 | $end_date = $start_date->copy()->addMonth(); |
||
191 | } |
||
192 | elseif($planId == 4) { |
||
193 | $end_date = $start_date->copy()->addMonths(3); |
||
194 | } |
||
195 | elseif($planId == 5) { |
||
196 | $end_date = $start_date->copy()->addMonths(6); |
||
197 | } |
||
198 | elseif($planId == 6) { |
||
199 | $end_date = $start_date->copy()->addMonths(12); |
||
200 | } |
||
201 | |||
202 | if($end_date->lt(Carbon::today())) { |
||
203 | $subscription_status = \constSubscription::Expired; |
||
204 | } |
||
205 | else { |
||
206 | $subscription_status = \constSubscription::onGoing; |
||
207 | } |
||
208 | |||
209 | $subscription = Subscription::create(['member_id'=> $member->id, |
||
210 | 'invoice_id'=> $invoice->id, |
||
211 | 'plan_id'=> (int) $planId, |
||
212 | 'start_date'=> $start_date->toDateString(), |
||
213 | 'end_date'=> $end_date->toDateString(), |
||
214 | 'status'=> $subscription_status, |
||
215 | 'is_renewal'=>'0', |
||
216 | 'created_by'=> Auth::user()->id, |
||
217 | 'updated_by'=> Auth::user()->id |
||
218 | ]); |
||
219 | |||
220 | $invoiceDetail = Invoice_detail::create(['invoice_id'=> $invoice->id, |
||
221 | 'plan_id'=> (int) $planId, |
||
222 | 'item_amount'=> $line->get('total_amount'), |
||
223 | 'item_amount'=> $line->get('total_amount'), |
||
224 | 'created_by'=> Auth::user()->id, |
||
225 | 'updated_by'=> Auth::user()->id |
||
226 | ]); |
||
227 | |||
228 | $paymentDetail = Payment_detail::create(['invoice_id'=> $invoice->id, |
||
229 | 'payment_amount'=> $payment_amount, |
||
230 | 'mode'=> '1', |
||
231 | 'note'=> ' ', |
||
232 | 'created_by'=> Auth::user()->id, |
||
233 | 'updated_by'=> Auth::user()->id |
||
234 | ]); |
||
235 | |||
236 | Setting::where('key', '=','invoice_last_number')->update(['value' => $invoiceCounter]); |
||
237 | Setting::where('key', '=','member_last_number')->update(['value' => $memberCounter]); |
||
238 | } |
||
239 | DB::commit(); |
||
240 | } |
||
241 | |||
242 | catch(\Exception $e) { |
||
243 | DB::rollback(); |
||
244 | dd($e); |
||
245 | } |
||
246 | echo "Ho gaya bc"; |
||
247 | } |
||
249 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths