Passed
Push — master ( 30672e...7bfc3b )
by Matthew
13:47 queued 08:22
created

TestStripe::getSubscription()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 82
Code Lines 68

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.4579

Importance

Changes 0
Metric Value
cc 4
eloc 68
nc 4
nop 2
dl 0
loc 82
ccs 11
cts 20
cp 0.55
crap 5.4579
rs 8.6981
c 0
b 0
f 0

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 MySociety\TheyWorkForYou;
4
5
class TestStripe extends Stripe {
6 1
    public function getSubscription($id, $args = []) {
7 1
        if ($id == 'sub_123') {
8 1
            return \Stripe\Util\Util::convertToStripeObject([
9 1
                'id' => 'sub_123',
10
                'discount' => [
11
                    'coupon' => ['percent_off' => 100],
12
                    'end' => null,
13
                ],
14
                'schedule' => null,
15
                'plan' => [
16
                    'amount' => '2000',
17
                    'id' => 'twfy-1k',
18
                    'nickname' => 'Some calls per month',
19
                    'interval' => 'month',
20
                ],
21 1
                'cancel_at_period_end' => false,
22 1
                'created' => time(),
23
                'current_period_end' => time(),
24
                'latest_invoice' => [],
25
                'customer' => [
26
                    'id' => 'cus_123',
27
                    'balance' => 0,
28
                    'default_source' => [],
29
                    'invoice_settings' => [
30
                        'default_payment_method' => [],
31
                    ],
32 1
                ],
33
            ], null);
34
        } elseif ($id == 'sub_456') {
35
            return \Stripe\Util\Util::convertToStripeObject([
36
                'id' => 'sub_456',
37 1
                'discount' => null,
38 1
                'schedule' => [
39
                    'id' => 'sub_sched',
40
                    'phases' => [
41
                    ],
42
                ],
43
                'plan' => [
44
                    'amount' => '4167',
45
                    'id' => 'twfy-5k',
46
                    'nickname' => 'Many calls per month',
47
                    'interval' => 'month',
48 1
                ],
49 1
                'cancel_at_period_end' => false,
50
                'created' => time(),
51
                'current_period_end' => time(),
52
                'latest_invoice' => [],
53
                'customer' => [
54
                    'id' => 'cus_456',
55
                    'balance' => 0,
56
                    'default_source' => [],
57
                    'invoice_settings' => [
58
                        'default_payment_method' => [],
59
                    ],
60
                ],
61
            ], null);
62
        } elseif ($id == 'sub_upgrade') {
63
            return \Stripe\Util\Util::convertToStripeObject([
64
                'id' => 'sub_upgrade',
65
                'discount' => null,
66
                'schedule' => null,
67
                'plan' => [
68
                    'amount' => '4167',
69
                    'id' => 'twfy-5k',
70
                    'nickname' => 'Many calls per month',
71
                    'interval' => 'month',
72
                ],
73
                'cancel_at_period_end' => false,
74
                'created' => time(),
75
                'current_period_end' => time(),
76
                'latest_invoice' => [],
77
                'customer' => [
78
                    'id' => 'cus_123',
79
                    'balance' => 0,
80
                    'default_source' => [],
81
                    'invoice_settings' => [
82
                        'default_payment_method' => [],
83
                    ],
84
                ],
85
            ], null);
86
        }
87
        return \Stripe\Util\Util::convertToStripeObject([], null);
88
    }
89
90
    public function getUpcomingInvoice($args) {
91
        return \Stripe\Util\Util::convertToStripeObject([], null);
92
    }
93
94
    public function createCustomer($args) {
95
        return \Stripe\Util\Util::convertToStripeObject([
96
            'id' => 'cus_123',
97
            'email' => '[email protected]',
98
        ], null);
99
    }
100
101
    public function updateCustomer($id, $args) {
102
        return \Stripe\Util\Util::convertToStripeObject([], null);
103
    }
104
105
    public function createSubscription($args) {
106
        if ($args['metadata']['charity_number'] == 'up-test') {
107
            $id = 'sub_upgrade';
108
        } elseif ($args['plan'] == 'twfy-5k') {
109
            $id = 'sub_456';
110
        } else {
111
            $id = 'sub_123';
112
        }
113
        return \Stripe\Util\Util::convertToStripeObject([
114
            'id' => $id,
115
        ], null);
116
    }
117
118
    public function createSchedule($id) {
119
        return \Stripe\Util\Util::convertToStripeObject([
120
            'id' => 'schedule_1',
121
            'phases' => [
122
                [
123
                    'start_date' => time(),
124
                    'end_date' => time(),
125
                    'discounts' => null,
126
                    'items' => [
127
                        [
128
                            'price' => '5000',
129
                        ],
130
                    ],
131
                ],
132
            ],
133
        ], null);
134
    }
135
136
    public function updateSchedule($id, $phases) {}
137
138
    public function releaseSchedule($id) {}
139
140
    public function updateSubscription($id, $args) {}
141
}
142