Total Complexity | 85 |
Total Lines | 618 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like FinancialTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FinancialTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class FinancialTest extends TestCase |
||
10 | { |
||
11 | protected function setUp(): void |
||
14 | } |
||
15 | |||
16 | /** |
||
17 | * @dataProvider providerAMORDEGRC |
||
18 | * |
||
19 | * @param mixed $expectedResult |
||
20 | */ |
||
21 | public function testAMORDEGRC($expectedResult, ...$args) |
||
22 | { |
||
23 | $result = Financial::AMORDEGRC(...$args); |
||
24 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
25 | } |
||
26 | |||
27 | public function providerAMORDEGRC() |
||
28 | { |
||
29 | return require 'tests/data/Calculation/Financial/AMORDEGRC.php'; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @dataProvider providerAMORLINC |
||
34 | * |
||
35 | * @param mixed $expectedResult |
||
36 | */ |
||
37 | public function testAMORLINC($expectedResult, ...$args) |
||
38 | { |
||
39 | $result = Financial::AMORLINC(...$args); |
||
40 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
41 | } |
||
42 | |||
43 | public function providerAMORLINC() |
||
44 | { |
||
45 | return require 'tests/data/Calculation/Financial/AMORLINC.php'; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @dataProvider providerCOUPDAYBS |
||
50 | * |
||
51 | * @param mixed $expectedResult |
||
52 | */ |
||
53 | public function testCOUPDAYBS($expectedResult, ...$args) |
||
54 | { |
||
55 | $result = Financial::COUPDAYBS(...$args); |
||
56 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
57 | } |
||
58 | |||
59 | public function providerCOUPDAYBS() |
||
60 | { |
||
61 | return require 'tests/data/Calculation/Financial/COUPDAYBS.php'; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @dataProvider providerCOUPDAYS |
||
66 | * |
||
67 | * @param mixed $expectedResult |
||
68 | */ |
||
69 | public function testCOUPDAYS($expectedResult, ...$args) |
||
70 | { |
||
71 | $result = Financial::COUPDAYS(...$args); |
||
72 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
73 | } |
||
74 | |||
75 | public function providerCOUPDAYS() |
||
76 | { |
||
77 | return require 'tests/data/Calculation/Financial/COUPDAYS.php'; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @dataProvider providerCOUPDAYSNC |
||
82 | * |
||
83 | * @param mixed $expectedResult |
||
84 | */ |
||
85 | public function testCOUPDAYSNC($expectedResult, ...$args) |
||
86 | { |
||
87 | $result = Financial::COUPDAYSNC(...$args); |
||
88 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
89 | } |
||
90 | |||
91 | public function providerCOUPDAYSNC() |
||
92 | { |
||
93 | return require 'tests/data/Calculation/Financial/COUPDAYSNC.php'; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @dataProvider providerCOUPNCD |
||
98 | * |
||
99 | * @param mixed $expectedResult |
||
100 | */ |
||
101 | public function testCOUPNCD($expectedResult, ...$args) |
||
102 | { |
||
103 | $result = Financial::COUPNCD(...$args); |
||
104 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
105 | } |
||
106 | |||
107 | public function providerCOUPNCD() |
||
108 | { |
||
109 | return require 'tests/data/Calculation/Financial/COUPNCD.php'; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @dataProvider providerCOUPNUM |
||
114 | * |
||
115 | * @param mixed $expectedResult |
||
116 | */ |
||
117 | public function testCOUPNUM($expectedResult, ...$args) |
||
118 | { |
||
119 | $result = Financial::COUPNUM(...$args); |
||
120 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
121 | } |
||
122 | |||
123 | public function providerCOUPNUM() |
||
124 | { |
||
125 | return require 'tests/data/Calculation/Financial/COUPNUM.php'; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @dataProvider providerCOUPPCD |
||
130 | * |
||
131 | * @param mixed $expectedResult |
||
132 | */ |
||
133 | public function testCOUPPCD($expectedResult, ...$args) |
||
134 | { |
||
135 | $result = Financial::COUPPCD(...$args); |
||
136 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
137 | } |
||
138 | |||
139 | public function providerCOUPPCD() |
||
140 | { |
||
141 | return require 'tests/data/Calculation/Financial/COUPPCD.php'; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @dataProvider providerCUMIPMT |
||
146 | * |
||
147 | * @param mixed $expectedResult |
||
148 | */ |
||
149 | public function testCUMIPMT($expectedResult, ...$args) |
||
153 | } |
||
154 | |||
155 | public function providerCUMIPMT() |
||
156 | { |
||
157 | return require 'tests/data/Calculation/Financial/CUMIPMT.php'; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @dataProvider providerCUMPRINC |
||
162 | * |
||
163 | * @param mixed $expectedResult |
||
164 | */ |
||
165 | public function testCUMPRINC($expectedResult, ...$args) |
||
166 | { |
||
167 | $result = Financial::CUMPRINC(...$args); |
||
168 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
169 | } |
||
170 | |||
171 | public function providerCUMPRINC() |
||
172 | { |
||
173 | return require 'tests/data/Calculation/Financial/CUMPRINC.php'; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @dataProvider providerDB |
||
178 | * |
||
179 | * @param mixed $expectedResult |
||
180 | */ |
||
181 | public function testDB($expectedResult, ...$args) |
||
182 | { |
||
183 | $result = Financial::DB(...$args); |
||
184 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
185 | } |
||
186 | |||
187 | public function providerDB() |
||
188 | { |
||
189 | return require 'tests/data/Calculation/Financial/DB.php'; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @dataProvider providerDDB |
||
194 | * |
||
195 | * @param mixed $expectedResult |
||
196 | */ |
||
197 | public function testDDB($expectedResult, ...$args) |
||
198 | { |
||
199 | $result = Financial::DDB(...$args); |
||
200 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
201 | } |
||
202 | |||
203 | public function providerDDB() |
||
204 | { |
||
205 | return require 'tests/data/Calculation/Financial/DDB.php'; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @dataProvider providerDISC |
||
210 | * |
||
211 | * @param mixed $expectedResult |
||
212 | */ |
||
213 | public function testDISC($expectedResult, ...$args) |
||
214 | { |
||
215 | $result = Financial::DISC(...$args); |
||
216 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
217 | } |
||
218 | |||
219 | public function providerDISC() |
||
220 | { |
||
221 | return require 'tests/data/Calculation/Financial/DISC.php'; |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * @dataProvider providerDOLLARDE |
||
226 | * |
||
227 | * @param mixed $expectedResult |
||
228 | */ |
||
229 | public function testDOLLARDE($expectedResult, ...$args) |
||
230 | { |
||
231 | $result = Financial::DOLLARDE(...$args); |
||
1 ignored issue
–
show
|
|||
232 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
233 | } |
||
234 | |||
235 | public function providerDOLLARDE() |
||
236 | { |
||
237 | return require 'tests/data/Calculation/Financial/DOLLARDE.php'; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * @dataProvider providerDOLLARFR |
||
242 | * |
||
243 | * @param mixed $expectedResult |
||
244 | */ |
||
245 | public function testDOLLARFR($expectedResult, ...$args) |
||
246 | { |
||
247 | $result = Financial::DOLLARFR(...$args); |
||
1 ignored issue
–
show
|
|||
248 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
249 | } |
||
250 | |||
251 | public function providerDOLLARFR() |
||
252 | { |
||
253 | return require 'tests/data/Calculation/Financial/DOLLARFR.php'; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * @dataProvider providerEFFECT |
||
258 | * |
||
259 | * @param mixed $expectedResult |
||
260 | */ |
||
261 | public function testEFFECT($expectedResult, ...$args) |
||
262 | { |
||
263 | $result = Financial::EFFECT(...$args); |
||
1 ignored issue
–
show
|
|||
264 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
265 | } |
||
266 | |||
267 | public function providerEFFECT() |
||
268 | { |
||
269 | return require 'tests/data/Calculation/Financial/EFFECT.php'; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * @dataProvider providerFV |
||
274 | * |
||
275 | * @param mixed $expectedResult |
||
276 | */ |
||
277 | public function testFV($expectedResult, ...$args) |
||
278 | { |
||
279 | $result = Financial::FV(...$args); |
||
1 ignored issue
–
show
|
|||
280 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
281 | } |
||
282 | |||
283 | public function providerFV() |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @dataProvider providerFVSCHEDULE |
||
290 | * |
||
291 | * @param mixed $expectedResult |
||
292 | */ |
||
293 | public function testFVSCHEDULE($expectedResult, ...$args) |
||
294 | { |
||
295 | $result = Financial::FVSCHEDULE(...$args); |
||
296 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
297 | } |
||
298 | |||
299 | public function providerFVSCHEDULE() |
||
300 | { |
||
301 | return require 'tests/data/Calculation/Financial/FVSCHEDULE.php'; |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * @dataProvider providerINTRATE |
||
306 | * |
||
307 | * @param mixed $expectedResult |
||
308 | */ |
||
309 | public function testINTRATE($expectedResult, ...$args) |
||
310 | { |
||
311 | $result = Financial::INTRATE(...$args); |
||
312 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
313 | } |
||
314 | |||
315 | public function providerINTRATE() |
||
316 | { |
||
317 | return require 'tests/data/Calculation/Financial/INTRATE.php'; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @dataProvider providerIPMT |
||
322 | * |
||
323 | * @param mixed $expectedResult |
||
324 | */ |
||
325 | public function testIPMT($expectedResult, ...$args) |
||
326 | { |
||
327 | $result = Financial::IPMT(...$args); |
||
328 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
329 | } |
||
330 | |||
331 | public function providerIPMT() |
||
332 | { |
||
333 | return require 'tests/data/Calculation/Financial/IPMT.php'; |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * @dataProvider providerIRR |
||
338 | * |
||
339 | * @param mixed $expectedResult |
||
340 | */ |
||
341 | public function testIRR($expectedResult, ...$args) |
||
342 | { |
||
343 | $result = Financial::IRR(...$args); |
||
1 ignored issue
–
show
|
|||
344 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
345 | } |
||
346 | |||
347 | public function providerIRR() |
||
348 | { |
||
349 | return require 'tests/data/Calculation/Financial/IRR.php'; |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * @dataProvider providerISPMT |
||
354 | * |
||
355 | * @param mixed $expectedResult |
||
356 | */ |
||
357 | public function testISPMT($expectedResult, ...$args) |
||
358 | { |
||
359 | $result = Financial::ISPMT(...$args); |
||
360 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
361 | } |
||
362 | |||
363 | public function providerISPMT() |
||
364 | { |
||
365 | return require 'tests/data/Calculation/Financial/ISPMT.php'; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * @dataProvider providerMIRR |
||
370 | * |
||
371 | * @param mixed $expectedResult |
||
372 | */ |
||
373 | public function testMIRR($expectedResult, ...$args) |
||
374 | { |
||
375 | $result = Financial::MIRR(...$args); |
||
376 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
377 | } |
||
378 | |||
379 | public function providerMIRR() |
||
380 | { |
||
381 | return require 'tests/data/Calculation/Financial/MIRR.php'; |
||
382 | } |
||
383 | |||
384 | /** |
||
385 | * @dataProvider providerNOMINAL |
||
386 | * |
||
387 | * @param mixed $expectedResult |
||
388 | */ |
||
389 | public function testNOMINAL($expectedResult, ...$args) |
||
390 | { |
||
391 | $result = Financial::NOMINAL(...$args); |
||
1 ignored issue
–
show
|
|||
392 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
393 | } |
||
394 | |||
395 | public function providerNOMINAL() |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * @dataProvider providerNPER |
||
402 | * |
||
403 | * @param mixed $expectedResult |
||
404 | */ |
||
405 | public function testNPER($expectedResult, ...$args) |
||
406 | { |
||
407 | $result = Financial::NPER(...$args); |
||
1 ignored issue
–
show
|
|||
408 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
409 | } |
||
410 | |||
411 | public function providerNPER() |
||
412 | { |
||
413 | return require 'tests/data/Calculation/Financial/NPER.php'; |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * @dataProvider providerNPV |
||
418 | * |
||
419 | * @param mixed $expectedResult |
||
420 | */ |
||
421 | public function testNPV($expectedResult, ...$args) |
||
422 | { |
||
423 | $result = Financial::NPV(...$args); |
||
424 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
425 | } |
||
426 | |||
427 | public function providerNPV() |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * @dataProvider providerPRICE |
||
434 | * |
||
435 | * @param mixed $expectedResult |
||
436 | */ |
||
437 | public function testPRICE($expectedResult, ...$args) |
||
438 | { |
||
439 | $result = Financial::PRICE(...$args); |
||
440 | self::assertEqualsWithDelta($expectedResult, $result, 1E-7); |
||
441 | } |
||
442 | |||
443 | public function providerPRICE() |
||
444 | { |
||
445 | return require 'tests/data/Calculation/Financial/PRICE.php'; |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * @dataProvider providerPRICE3 |
||
450 | * |
||
451 | * @param mixed $expectedResult |
||
452 | */ |
||
453 | public function testPRICE3($expectedResult, ...$args) |
||
454 | { |
||
455 | // These results (PRICE function with basis codes 2 and 3) |
||
456 | // agree with published algorithm, LibreOffice, and Gnumeric. |
||
457 | // They do not agree with Excel. |
||
458 | $result = Financial::PRICE(...$args); |
||
459 | self::assertEqualsWithDelta($expectedResult, $result, 1E-7); |
||
460 | } |
||
461 | |||
462 | public function providerPRICE3() |
||
463 | { |
||
464 | return require 'data/Calculation/Financial/PRICE3.php'; |
||
465 | } |
||
466 | |||
467 | /** |
||
468 | * @dataProvider providerPRICEDISC |
||
469 | * |
||
470 | * @param mixed $expectedResult |
||
471 | */ |
||
472 | public function testPRICEDISC($expectedResult, array $args) |
||
473 | { |
||
474 | $result = Financial::PRICEDISC(...$args); |
||
475 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
476 | } |
||
477 | |||
478 | public function providerPRICEDISC() |
||
479 | { |
||
480 | return require 'tests/data/Calculation/Financial/PRICEDISC.php'; |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * @dataProvider providerPV |
||
485 | * |
||
486 | * @param mixed $expectedResult |
||
487 | */ |
||
488 | public function testPV($expectedResult, array $args) |
||
489 | { |
||
490 | $result = Financial::PV(...$args); |
||
1 ignored issue
–
show
|
|||
491 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
492 | } |
||
493 | |||
494 | public function providerPV() |
||
495 | { |
||
496 | return require 'tests/data/Calculation/Financial/PV.php'; |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * @dataProvider providerRATE |
||
501 | * |
||
502 | * @param mixed $expectedResult |
||
503 | */ |
||
504 | public function testRATE($expectedResult, ...$args) |
||
508 | } |
||
509 | |||
510 | public function providerRATE() |
||
513 | } |
||
514 | |||
515 | /** |
||
516 | * @dataProvider providerXIRR |
||
517 | * |
||
518 | * @param mixed $expectedResult |
||
519 | * @param mixed $message |
||
520 | */ |
||
521 | public function testXIRR($expectedResult, $message, ...$args) |
||
522 | { |
||
523 | $result = Financial::XIRR(...$args); |
||
524 | if (is_numeric($result) && is_numeric($expectedResult)) { |
||
525 | if ($expectedResult != 0) { |
||
526 | $frac = $result / $expectedResult; |
||
527 | if ($frac > 0.999999 && $frac < 1.000001) { |
||
528 | $result = $expectedResult; |
||
529 | } |
||
530 | } |
||
531 | } |
||
532 | self::assertEquals($expectedResult, $result, $message); |
||
533 | } |
||
534 | |||
535 | public function providerXIRR() |
||
536 | { |
||
537 | return require 'tests/data/Calculation/Financial/XIRR.php'; |
||
538 | } |
||
539 | |||
540 | /** |
||
541 | * @dataProvider providerXNPV |
||
542 | * |
||
543 | * @param mixed $expectedResult |
||
544 | * @param mixed $message |
||
545 | */ |
||
546 | public function testXNPV($expectedResult, $message, ...$args) |
||
547 | { |
||
548 | $result = Financial::XNPV(...$args); |
||
549 | if (is_numeric($result) && is_numeric($expectedResult)) { |
||
550 | if ($expectedResult != 0) { |
||
551 | $frac = $result / $expectedResult; |
||
552 | if ($frac > 0.999999 && $frac < 1.000001) { |
||
553 | $result = $expectedResult; |
||
554 | } |
||
555 | } |
||
556 | } |
||
557 | self::assertEquals($expectedResult, $result, $message); |
||
558 | } |
||
559 | |||
560 | public function providerXNPV() |
||
561 | { |
||
562 | return require 'data/Calculation/Financial/XNPV.php'; |
||
563 | } |
||
564 | |||
565 | /** |
||
566 | * @dataProvider providerPDURATION |
||
567 | * |
||
568 | * @param mixed $expectedResult |
||
569 | */ |
||
570 | public function testPDURATION($expectedResult, array $args) |
||
571 | { |
||
572 | $result = Financial::PDURATION(...$args); |
||
1 ignored issue
–
show
|
|||
573 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
574 | } |
||
575 | |||
576 | public function providerPDURATION() |
||
577 | { |
||
578 | return require 'tests/data/Calculation/Financial/PDURATION.php'; |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * @dataProvider providerRRI |
||
583 | * |
||
584 | * @param mixed $expectedResult |
||
585 | */ |
||
586 | public function testRRI($expectedResult, array $args) |
||
590 | } |
||
591 | |||
592 | public function providerRRI() |
||
593 | { |
||
594 | return require 'tests/data/Calculation/Financial/RRI.php'; |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * @dataProvider providerSLN |
||
599 | * |
||
600 | * @param mixed $expectedResult |
||
601 | */ |
||
602 | public function testSLN($expectedResult, array $args) |
||
603 | { |
||
604 | $result = Financial::SLN(...$args); |
||
605 | self::assertEqualsWithDelta($expectedResult, $result, 1E-8); |
||
606 | } |
||
607 | |||
608 | public function providerSLN() |
||
609 | { |
||
610 | return require 'tests/data/Calculation/Financial/SLN.php'; |
||
611 | } |
||
612 | |||
613 | /** |
||
614 | * @dataProvider providerSYD |
||
615 | * |
||
616 | * @param mixed $expectedResult |
||
617 | */ |
||
618 | public function testSYD($expectedResult, array $args) |
||
622 | } |
||
623 | |||
624 | public function providerSYD() |
||
625 | { |
||
626 | return require 'tests/data/Calculation/Financial/SYD.php'; |
||
627 | } |
||
628 | } |
||
629 |