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