Conditions | 4 |
Paths | 6 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
17 | 7 | public static function generate(PaymentScheduleConfigInterface $paymentScheduleConfig): PaymentScheduleInterface |
|
18 | { |
||
19 | 7 | $schedule = new PaymentSchedule($paymentScheduleConfig); |
|
20 | |||
21 | 7 | $startDate = $paymentScheduleConfig->getStartDate(); |
|
22 | 7 | $dateInterval = $paymentScheduleConfig->getDateInterval(); |
|
23 | 7 | $noOfPayments = $paymentScheduleConfig->getNoOfPayments(); |
|
24 | 7 | $firstPaymentDate = $paymentScheduleConfig->getFirstPaymentDate(); |
|
25 | |||
26 | 7 | if (!is_null($firstPaymentDate)){ |
|
27 | 4 | $startDate = $firstPaymentDate; |
|
28 | 4 | $schedule->add($startDate, 1); |
|
29 | } |
||
30 | |||
31 | 7 | $period = new \DatePeriod($startDate, $dateInterval, ($noOfPayments - $schedule->getNoOfPayments())); |
|
32 | |||
33 | 7 | foreach ($period as $iteration => $date) { |
|
34 | 7 | if ($date != $startDate) { |
|
35 | 7 | $schedule->add($date, $schedule->getNoOfPayments() + 1); |
|
36 | } |
||
37 | } |
||
38 | |||
39 | 7 | return $schedule; |
|
40 | } |
||
41 | } |