Stripe   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 27.78%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 56
ccs 5
cts 18
cp 0.2778
rs 10
c 0
b 0
f 0
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A releaseSchedule() 0 2 1
A getInvoices() 0 2 1
A getSubscription() 0 2 1
A createCustomer() 0 2 1
A createSchedule() 0 2 1
A __construct() 0 11 3
A updateCustomer() 0 2 1
A updateSchedule() 0 2 1
A updateSubscription() 0 2 1
A createSubscription() 0 2 1
A getUpcomingInvoice() 0 2 1
1
<?php
2
3
namespace MySociety\TheyWorkForYou;
4
5
class Stripe {
6
    private static $instance;
7
8 1
    public function __construct($stripeSecretKey = "") {
9 1
        if (self::$instance) {
10
            throw new \RuntimeException('Stripe could not be instantiate more than once. Check PHP implementation : https://github.com/stripe/stripe-php');
11
        }
12 1
        self::$instance = $this;
13
14 1
        # Not present in testing
15 1
        if ($stripeSecretKey) {
16
            $this->client = new \Stripe\StripeClient([
0 ignored issues
show
Bug Best Practice introduced by
The property client does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
                "api_key" => $stripeSecretKey,
18
                "stripe_version" => STRIPE_API_VERSION,
0 ignored issues
show
Bug introduced by
The constant MySociety\TheyWorkForYou\STRIPE_API_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
19
            ]);
20
        }
21
    }
22
23
    public function getSubscription($id, $args = []) {
24
        return $this->client->subscriptions->retrieve($id, $args);
25
    }
26
27
    public function getUpcomingInvoice($args) {
28
        return $this->client->invoices->upcoming($args);
29
    }
30
31
    public function createCustomer($args) {
32
        return $this->client->customers->create($args);
33
    }
34
35
    public function updateCustomer($id, $args) {
36
        return $this->client->customers->update($id, $args);
37
    }
38
39
    public function createSubscription($args) {
40
        return $this->client->subscriptions->create($args);
41
    }
42
43
    public function getInvoices($args) {
44
        return $this->client->invoices->all($args);
45
    }
46
47
    public function createSchedule($id) {
48
        return $this->client->subscriptionSchedules->create(['from_subscription' => $id]);
49
    }
50
51
    public function updateSchedule($id, $phases) {
52
        return $this->client->subscriptionSchedules->update($id, ['phases' => $phases]);
53
    }
54
55
    public function releaseSchedule($id) {
56
        $this->client->subscriptionSchedules->release($id);
57
    }
58
59
    public function updateSubscription($id, $args) {
60
        $this->client->subscriptions->update($id, $args);
61
    }
62
}
63