InvoiceItem   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 14
c 1
b 0
f 0
dl 0
loc 99
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A startDate() 0 4 2
A endDate() 0 4 2
A asStripeInvoiceItem() 0 3 1
A __construct() 0 4 1
A isSubscription() 0 3 1
A total() 0 3 1
A __get() 0 3 1
A formatAmount() 0 3 1
1
<?php
2
3
namespace Phalcon\Cashier;
4
5
class InvoiceItem
6
{
7
    /**
8
     * The user instance.
9
     *
10
     */
11
    protected $user;
12
13
    /**
14
     * The Stripe invoice item instance.
15
     *
16
     * @var \Stripe\InvoiceItem
17
     */
18
    protected $item;
19
20
    /**
21
     * Create a new invoice item instance.
22
     * @return void
23
     */
24
    public function __construct($user, $item)
25
    {
26
        $this->user = $user;
27
        $this->item = $item;
28
    }
29
30
    /**
31
     * Get the total for the line item.
32
     *
33
     * @return string
34
     */
35
    public function total()
36
    {
37
        return $this->formatAmount($this->amount);
0 ignored issues
show
Bug Best Practice introduced by
The property amount does not exist on Phalcon\Cashier\InvoiceItem. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
    }
39
40
    /**
41
     * Get a human readable date for the start date.
42
     *
43
     * @return string
44
     */
45
    public function startDate()
46
    {
47
        if ($this->isSubscription()) {
48
            return date('M j, Y', $this->item->period->start);
49
        }
50
    }
51
52
    /**
53
     * Get a human readable date for the end date.
54
     *
55
     * @return string
56
     */
57
    public function endDate()
58
    {
59
        if ($this->isSubscription()) {
60
            return date('M j, Y', $this->item->period->end);
61
        }
62
    }
63
64
    /**
65
     * Determine if the invoice item is for a subscription.
66
     *
67
     * @return bool
68
     */
69
    public function isSubscription()
70
    {
71
        return $this->item->type === 'subscription';
72
    }
73
74
    /**
75
     * Format the given amount into a string based on the user's preferences.
76
     *
77
     * @param  int  $amount
78
     * @return string
79
     */
80
    protected function formatAmount($amount)
81
    {
82
        return Cashier::formatAmount($amount);
83
    }
84
85
    /**
86
     * Get the underlying Stripe invoice item.
87
     *
88
     * @return \Stripe\StripeObject
89
     */
90
    public function asStripeInvoiceItem()
91
    {
92
        return $this->item;
93
    }
94
95
    /**
96
     * Dynamically access the Stripe line item instance.
97
     *
98
     * @param  string  $key
99
     * @return mixed
100
     */
101
    public function __get($key)
102
    {
103
        return $this->item->{$key};
104
    }
105
}
106