Completed
Pull Request — master (#47)
by ARCANEDEV
15:14 queued 12:50
created

Transfer::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\Transfer as TransferContract;
4
use Arcanedev\Stripe\StripeResource;
5
6
/**
7
 * Class     Transfer
8
 *
9
 * @package  Arcanedev\Stripe\Resources
10
 * @author   ARCANEDEV <[email protected]>
11
 * @link     https://stripe.com/docs/api/php#transfer_object
12
 *
13
 * @property  string                                   id
14
 * @property  string                                   object                // 'transfer'
15
 * @property  int                                      amount
16
 * @property  int                                      amount_reversed
17
 * @property  string                                   application_fee
18
 * @property  string                                   balance_transaction
19
 * @property  int                                      created               // timestamp
20
 * @property  string                                   currency
21
 * @property  int                                      date                  // timestamp
22
 * @property  string                                   description
23
 * @property  string                                   destination
24
 * @property  string                                   destination_payment
25
 * @property  string                                   failure_code
26
 * @property  string                                   failure_message
27
 * @property  bool                                     livemode
28
 * @property  \Arcanedev\Stripe\AttachedObject         metadata
29
 * @property  \Arcanedev\Stripe\Collection             reversals
30
 * @property  bool                                     reversed
31
 * @property  string                                   source_transaction
32
 * @property  string                                   source_type           // 'card', 'bank_account', 'bitcoin_receiver', or 'alipay_account'
33
 * @property  string                                   statement_descriptor
34
 * @property  string                                   status                // 'paid', 'pending', 'in_transit', 'canceled' or 'failed'
35
 * @property  string                                   type                  //  'card', 'bank_account', or 'stripe_account'
36
 */
37
class Transfer extends StripeResource implements TransferContract
38
{
39
    /* ------------------------------------------------------------------------------------------------
40
     |  Main Functions
41
     | ------------------------------------------------------------------------------------------------
42
     */
43
    /**
44
     * List all Transfers.
45
     * @link   https://stripe.com/docs/api/php#list_transfers
46
     *
47
     * @param  array|null         $params
48
     * @param  array|string|null  $options
49
     *
50
     * @return \Arcanedev\Stripe\Collection|array
51
     */
52 4
    public static function all($params = [], $options = null)
53
    {
54 4
        return self::scopedAll($params, $options);
55
    }
56
57
    /**
58
     * Retrieve a Transfer.
59
     * @link   https://stripe.com/docs/api/php#retrieve_transfer
60
     *
61
     * @param  string             $id
62
     * @param  array|string|null  $options
63
     *
64
     * @return self
65
     */
66
    public static function retrieve($id, $options = null)
67
    {
68
        return self::scopedRetrieve($id, $options);
69
    }
70
71
    /**
72
     * Create a transfer.
73
     * @link   https://stripe.com/docs/api/php#create_transfer
74
     *
75
     * @param  array|null         $params
76
     * @param  array|string|null  $options
77
     *
78
     * @return self|array
79
     */
80 14
    public static function create($params = [], $options = null)
81
    {
82 14
        return self::scopedCreate($params, $options);
83
    }
84
85
    /**
86
     * Update a Transfer.
87
     * @link   https://stripe.com/docs/api/php#update_transfer
88
     *
89
     * @param  string             $id
90
     * @param  array|null         $params
91
     * @param  array|string|null  $options
92
     *
93
     * @return self
94
     */
95
    public static function update($id, $params = [], $options = null)
96
    {
97
        return self::scopedUpdate($id, $params, $options);
98
    }
99
100
    /**
101
     * Update/Save a Transfer.
102
     * @link   https://stripe.com/docs/api/php#update_transfer
103
     *
104
     * @param  array|string|null  $options
105
     *
106
     * @return self
107
     */
108
    public function save($options = null)
109
    {
110
        return self::scopedSave($options);
111
    }
112
113
    /**
114
     * Cancel a Transfer.
115
     * @link   https://stripe.com/docs/api/php#cancel_transfer
116
     *
117
     * @return self
118
     */
119
    public function cancel()
120
    {
121
        list($response, $opts) = $this->request('post', $this->instanceUrl().'/cancel');
122
        $this->refreshFrom($response, $opts);
123
124
        return $this;
125
    }
126
127
    /**
128
     * Created transfer reversal.
129
     *
130
     * @param  array|null         $params
131
     * @param  array|string|null  $options
132
     *
133
     * @return \Arcanedev\Stripe\Resources\TransferReversal
134
     */
135
    public function reverse($params = [], $options = null)
136
    {
137
        list($response, $opts) = $this->request(
138
            'post', $this->instanceUrl().'/reversals', $params, $options
139
        );
140
        $this->refreshFrom($response, $opts);
141
142
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Arcanedev\Stripe\Resources\Transfer) is incompatible with the return type declared by the interface Arcanedev\Stripe\Contrac...urces\Transfer::reverse of type Arcanedev\Stripe\Contrac...ources\TransferReversal.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
143
    }
144
}
145