Conditions | 1 |
Paths | 1 |
Total Lines | 195 |
Code Lines | 130 |
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 |
||
129 | public function providerGetAllToInvoice(): array |
||
130 | { |
||
131 | $normal = [ |
||
132 | [ |
||
133 | 'role' => User::ROLE_MEMBER, |
||
134 | 'status' => User::STATUS_ACTIVE, |
||
135 | 'bookings' => [ |
||
136 | [ |
||
137 | 'start_date' => '2019-02-25', |
||
138 | 'end_date' => null, |
||
139 | 'status' => BookingStatusType::BOOKED, |
||
140 | 'bookable' => [ |
||
141 | 'name' => 'cotisation', |
||
142 | 'booking_type' => BookingTypeType::MANDATORY, |
||
143 | 'is_active' => true, |
||
144 | 'periodic_price' => '25.00', |
||
145 | ], |
||
146 | ], |
||
147 | [ |
||
148 | 'start_date' => '2020-01-01', |
||
149 | 'end_date' => null, |
||
150 | 'status' => BookingStatusType::BOOKED, |
||
151 | 'bookable' => [ |
||
152 | 'name' => 'casier', |
||
153 | 'booking_type' => BookingTypeType::ADMIN_ONLY, |
||
154 | 'is_active' => true, |
||
155 | 'periodic_price' => '25.00', |
||
156 | ], |
||
157 | ], |
||
158 | ], |
||
159 | 'account' => [ |
||
160 | 'transaction_lines' => [ |
||
161 | [ |
||
162 | 'balance' => '5.00', |
||
163 | 'transactionDate' => '2019-02-25', |
||
164 | ], |
||
165 | ], |
||
166 | ], |
||
167 | ], |
||
168 | ]; |
||
169 | |||
170 | $inactiveUser = $normal; |
||
171 | $inactiveUser[0]['status'] = User::STATUS_INACTIVE; |
||
172 | |||
173 | $archivedUser = $normal; |
||
174 | $archivedUser[0]['status'] = User::STATUS_ARCHIVED; |
||
175 | |||
176 | $newUser = $normal; |
||
177 | $newUser[0]['status'] = User::STATUS_NEW; |
||
178 | |||
179 | $anonymousUser = $normal; |
||
180 | $anonymousUser[0]['role'] = User::ROLE_ANONYMOUS; |
||
181 | |||
182 | $bookingOnlyUser = $normal; |
||
183 | $bookingOnlyUser[0]['role'] = User::ROLE_BOOKING_ONLY; |
||
184 | |||
185 | $individualUser = $normal; |
||
186 | $individualUser[0]['role'] = User::ROLE_INDIVIDUAL; |
||
187 | |||
188 | $responsibleUser = $normal; |
||
189 | $responsibleUser[0]['role'] = User::ROLE_RESPONSIBLE; |
||
190 | |||
191 | $administratorUser = $normal; |
||
192 | $administratorUser[0]['role'] = User::ROLE_ADMINISTRATOR; |
||
193 | |||
194 | $futureBookingThisYear = $normal; |
||
195 | $futureBookingThisYear[0]['bookings'][0]['start_date'] = '2019-12-31'; |
||
196 | |||
197 | $futureBookingNextYear = $normal; |
||
198 | $futureBookingNextYear[0]['bookings'][0]['start_date'] = '2021-01-01'; |
||
199 | |||
200 | $terminatedBooking = $normal; |
||
201 | $terminatedBooking[0]['bookings'][0]['end_date'] = '2019-01-01'; |
||
202 | |||
203 | $terminatedBooking = $normal; |
||
204 | $terminatedBooking[0]['bookings'][0]['end_date'] = '2019-01-01'; |
||
205 | |||
206 | $terminatedBookingNextYear = $normal; |
||
207 | $terminatedBookingNextYear[0]['bookings'][0]['end_date'] = '2021-01-01'; |
||
208 | |||
209 | $applicationBooking = $normal; |
||
210 | $applicationBooking[0]['bookings'][0]['status'] = BookingStatusType::APPLICATION; |
||
211 | |||
212 | $processedBooking = $normal; |
||
213 | $processedBooking[0]['bookings'][0]['status'] = BookingStatusType::PROCESSED; |
||
214 | |||
215 | $selfApprovedBookable = $normal; |
||
216 | $selfApprovedBookable[0]['bookings'][0]['bookable']['booking_type'] = BookingTypeType::SELF_APPROVED; |
||
217 | |||
218 | $adminApprovedBookable = $normal; |
||
219 | $adminApprovedBookable[0]['bookings'][0]['bookable']['booking_type'] = BookingTypeType::ADMIN_APPROVED; |
||
220 | |||
221 | $inactiveBookable = $normal; |
||
222 | $inactiveBookable[0]['bookings'][0]['bookable']['is_active'] = false; |
||
223 | |||
224 | $freeBookable = $normal; |
||
225 | $freeBookable[0]['bookings'][0]['bookable']['periodic_price'] = 0; |
||
226 | |||
227 | $negativeBookable = $normal; |
||
228 | $negativeBookable[0]['bookings'][0]['bookable']['periodic_price'] = -10; |
||
229 | |||
230 | $existingTransactionThisYear = $normal; |
||
231 | $existingTransactionThisYear[0]['account']['transaction_lines'][0]['transactionDate'] = '2020-02-01'; |
||
232 | |||
233 | $existingTransactionNextYear = $normal; |
||
234 | $existingTransactionNextYear[0]['account']['transaction_lines'][0]['transactionDate'] = '2021-02-01'; |
||
235 | |||
236 | return [ |
||
237 | 'normal user get casier and cotisation' => [ |
||
238 | $normal, |
||
239 | ['casier', 'cotisation'], |
||
240 | ], |
||
241 | 'inactive user get casier and cotisation' => [ |
||
242 | $inactiveUser, |
||
243 | ['casier', 'cotisation'], |
||
244 | ], |
||
245 | 'archived user get nothing' => [ |
||
246 | $archivedUser, |
||
247 | [], |
||
248 | ], |
||
249 | 'new user get nothing' => [ |
||
250 | $newUser, |
||
251 | [], |
||
252 | ], |
||
253 | 'anonymous user get nothing' => [ |
||
254 | $anonymousUser, |
||
255 | [], |
||
256 | ], |
||
257 | 'bookingOnly user get nothing' => [ |
||
258 | $bookingOnlyUser, |
||
259 | [], |
||
260 | ], |
||
261 | 'individual user get nothing' => [ |
||
262 | $individualUser, |
||
263 | [], |
||
264 | ], |
||
265 | 'responsible user get casier and cotisation' => [ |
||
266 | $responsibleUser, |
||
267 | ['casier', 'cotisation'], |
||
268 | ], |
||
269 | 'administrator user get casier and cotisation' => [ |
||
270 | $administratorUser, |
||
271 | ['casier', 'cotisation'], |
||
272 | ], |
||
273 | 'future booking this year are still counted' => [ |
||
274 | $futureBookingThisYear, |
||
275 | ['casier', 'cotisation'], |
||
276 | ], |
||
277 | 'future booking next year are not yet counted' => [ |
||
278 | $futureBookingNextYear, |
||
279 | ['casier'], |
||
280 | ], |
||
281 | 'terminated booking are not counted anymore' => [ |
||
282 | $terminatedBooking, |
||
283 | ['casier'], |
||
284 | ], |
||
285 | 'terminated booking next year are not yet terminated so must be counted' => [ |
||
286 | $terminatedBookingNextYear, |
||
287 | ['casier', 'cotisation'], |
||
288 | ], |
||
289 | 'application booking is ignored' => [ |
||
290 | $applicationBooking, |
||
291 | ['casier'], |
||
292 | ], |
||
293 | 'processsed booking is ignored' => [ |
||
294 | $processedBooking, |
||
295 | ['casier'], |
||
296 | ], |
||
297 | 'self approvable bookable is not counted' => [ |
||
298 | $selfApprovedBookable, |
||
299 | ['casier'], |
||
300 | ], |
||
301 | 'admin approvable bookable is not counted' => [ |
||
302 | $adminApprovedBookable, |
||
303 | ['casier'], |
||
304 | ], |
||
305 | 'inactive bookable is not counted' => [ |
||
306 | $inactiveBookable, |
||
307 | ['casier'], |
||
308 | ], |
||
309 | 'free bookable is not counted' => [ |
||
310 | $freeBookable, |
||
311 | ['casier'], |
||
312 | ], |
||
313 | 'negative bookable is counted' => [ |
||
314 | $negativeBookable, |
||
315 | ['casier', 'cotisation'], |
||
316 | ], |
||
317 | 'existing transaction for this year should not be re-created' => [ |
||
318 | $existingTransactionThisYear, |
||
319 | ['cotisation'], |
||
320 | ], |
||
321 | 'existing transaction for next year have no impact' => [ |
||
322 | $existingTransactionNextYear, |
||
323 | ['casier', 'cotisation'], |
||
324 | ], |
||
343 |