Completed
Push — master ( 388c50...c3616e )
by ARCANEDEV
8s
created

Transfer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 108
c 2
b 0
f 0
ccs 8
cts 20
cp 0.4
rs 10
wmc 7
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A retrieve() 0 4 1
A create() 0 4 1
A update() 0 4 1
A save() 0 4 1
A cancel() 0 7 1
A reverse() 0 9 1
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                            balance_transaction
18
 * @property  int                               created               // timestamp
19
 * @property  string                            currency
20
 * @property  int                               date                  // timestamp
21
 * @property  string                            destination
22
 * @property  string                            destination_payment
23
 * @property  bool                              livemode
24
 * @property  \Arcanedev\Stripe\AttachedObject  metadata
25
 * @property  \Arcanedev\Stripe\Collection      reversals
26
 * @property  bool                              reversed
27
 * @property  string                            source_transaction
28
 */
29
class Transfer extends StripeResource implements TransferContract
30
{
31
    /* ------------------------------------------------------------------------------------------------
32
     |  Main Functions
33
     | ------------------------------------------------------------------------------------------------
34
     */
35
    /**
36
     * List all Transfers.
37
     * @link   https://stripe.com/docs/api/php#list_transfers
38
     *
39
     * @param  array|null         $params
40
     * @param  array|string|null  $options
41
     *
42
     * @return \Arcanedev\Stripe\Collection|array
43
     */
44 2
    public static function all($params = [], $options = null)
45
    {
46 2
        return self::scopedAll($params, $options);
47
    }
48
49
    /**
50
     * Retrieve a Transfer.
51
     * @link   https://stripe.com/docs/api/php#retrieve_transfer
52
     *
53
     * @param  string             $id
54
     * @param  array|string|null  $options
55
     *
56
     * @return self
57
     */
58 6
    public static function retrieve($id, $options = null)
59
    {
60 6
        return self::scopedRetrieve($id, $options);
61
    }
62
63
    /**
64
     * Create a transfer.
65
     * @link   https://stripe.com/docs/api/php#create_transfer
66
     *
67
     * @param  array|null         $params
68
     * @param  array|string|null  $options
69
     *
70
     * @return self|array
71
     */
72 10
    public static function create($params = [], $options = null)
73
    {
74 10
        return self::scopedCreate($params, $options);
75
    }
76
77
    /**
78
     * Update a Transfer.
79
     * @link   https://stripe.com/docs/api/php#update_transfer
80
     *
81
     * @param  string             $id
82
     * @param  array|null         $params
83
     * @param  array|string|null  $options
84
     *
85
     * @return self
86
     */
87
    public static function update($id, $params = [], $options = null)
88
    {
89
        return self::scopedUpdate($id, $params, $options);
90
    }
91
92
    /**
93
     * Update/Save a Transfer.
94
     * @link   https://stripe.com/docs/api/php#update_transfer
95
     *
96
     * @param  array|string|null  $options
97
     *
98
     * @return self
99
     */
100 4
    public function save($options = null)
101
    {
102 4
        return self::scopedSave($options);
103
    }
104
105
    /**
106
     * Cancel a Transfer.
107
     * @link   https://stripe.com/docs/api/php#cancel_transfer
108
     *
109
     * @return self
110
     */
111
    public function cancel()
112
    {
113
        list($response, $opts) = $this->request('post', $this->instanceUrl().'/cancel');
114
        $this->refreshFrom($response, $opts);
115
116
        return $this;
117
    }
118
119
    /**
120
     * Created transfer reversal.
121
     *
122
     * @param  array|null         $params
123
     * @param  array|string|null  $options
124
     *
125
     * @return \Arcanedev\Stripe\Resources\TransferReversal
126
     */
127
    public function reverse($params = [], $options = null)
128
    {
129
        list($response, $opts) = $this->request(
130
            'post', $this->instanceUrl().'/reversals', $params, $options
131
        );
132
        $this->refreshFrom($response, $opts);
133
134
        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...
135
    }
136
}
137