CalculateNextChargeTest::data_for()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 35
c 2
b 0
f 1
nc 1
nop 0
dl 0
loc 64
rs 9.36

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace ByTIC\Payments\Tests\Actions\Subscriptions\Charges;
4
5
use ByTIC\Payments\Actions\Subscriptions\Charges\CalculateNextCharge;
6
use ByTIC\Payments\Models\Subscriptions\Subscription;
7
use ByTIC\Payments\Subscriptions\Billing\BillingPeriod;
8
9
/**
10
 * Class CalculateNextChargeTest
11
 * @package ByTIC\Payments\Tests\Actions\Subscriptions\Charges
12
 */
13
class CalculateNextChargeTest extends \ByTIC\Payments\Tests\AbstractTestCase
14
{
15
    /**
16
     * @dataProvider data_for
17
     */
18
    public function test_for($data, $result)
19
    {
20
        $subscription = new Subscription();
21
        $subscription->fill($data);
22
23
        CalculateNextCharge::for($subscription);
24
25
        self::assertEquals($result, $subscription->getPropertyRaw('charge_at'));
26
    }
27
28
    public function data_for(): array
29
    {
30
        return [
31
            [
32
                [
33
                    'start_at' => '2020-01-01',
34
                    'charge_count' => '',
35
                    'billing_period' => BillingPeriod::DAILY,
36
                    'billing_interval' => 1
37
                ],
38
                '2020-01-02 08:00:00',
39
            ],
40
            [
41
                [
42
                    'start_at' => '2020-01-01',
43
                    'charge_count' => 4,
44
                    'billing_period' => BillingPeriod::DAILY,
45
                    'billing_interval' => 1
46
                ],
47
                '2020-01-05 08:00:00',
48
            ],
49
            [
50
                [
51
                    'start_at' => '2020-01-01',
52
                    'billing_period' => BillingPeriod::MONTHLY,
53
                    'billing_interval' => 1
54
                ],
55
                '2020-02-01 08:00:00',
56
            ],
57
            [
58
                [
59
                    'start_at' => '2021-05-31 00:00:00',
60
                    'charge_count' => '',
61
                    'billing_period' => BillingPeriod::MONTHLY,
62
                    'billing_interval' => 1
63
                ],
64
                '2021-06-30 08:00:00',
65
            ],
66
            [
67
                [
68
                    'start_at' => '2021-05-30 00:00:00',
69
                    'charge_count' => '',
70
                    'billing_period' => BillingPeriod::MONTHLY,
71
                    'billing_interval' => 1
72
                ],
73
                '2021-06-30 08:00:00',
74
            ],
75
            [
76
                [
77
                    'start_at' => '2021-06-30 00:00:00',
78
                    'charge_count' => '',
79
                    'billing_period' => BillingPeriod::MONTHLY,
80
                    'billing_interval' => 1
81
                ],
82
                '2021-07-30 08:00:00',
83
            ],
84
            [
85
                [
86
                    'start_at' => '2021-05-31 00:00:00',
87
                    'charge_count' => 2,
88
                    'billing_period' => BillingPeriod::MONTHLY,
89
                    'billing_interval' => 1
90
                ],
91
                '2021-07-31 08:00:00',
92
            ]
93
        ];
94
    }
95
}
96