Test Failed
Push — master ( 3dd85e...34f16b )
by Devin
04:34 queued 10s
created

BankAccount   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 12
loc 84
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
A verify() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Stripe;
4
5
/**
6
 * Class BankAccount
7
 *
8
 * @property string $id
9
 * @property string $object
10
 * @property string $account
11
 * @property string $account_holder_name
12
 * @property string $account_holder_type
13
 * @property string $bank_name
14
 * @property string $country
15
 * @property string $currency
16
 * @property string $customer
17
 * @property bool $default_for_currency
18
 * @property string $fingerprint
19
 * @property string $last4
20
 * @property StripeObject $metadata
21
 * @property string $routing_number
22
 * @property string $status
23
 *
24
 * @package Stripe
25
 */
26
class BankAccount extends ApiResource
27
{
28
29
    const OBJECT_NAME = "bank_account";
30
31
    use ApiOperations\Delete;
32
    use ApiOperations\Update;
33
34
    /**
35
     * Possible string representations of the bank verification status.
36
     * @link https://stripe.com/docs/api/external_account_bank_accounts/object#account_bank_account_object-status
37
     */
38
    const STATUS_NEW                 = 'new';
39
    const STATUS_VALIDATED           = 'validated';
40
    const STATUS_VERIFIED            = 'verified';
41
    const STATUS_VERIFICATION_FAILED = 'verification_failed';
42
    const STATUS_ERRORED             = 'errored';
43
44
    /**
45
     * @return string The instance URL for this resource. It needs to be special
46
     *    cased because it doesn't fit into the standard resource pattern.
47
     */
48
    public function instanceUrl()
49
    {
50
        if ($this['customer']) {
51
            $base = Customer::classUrl();
52
            $parent = $this['customer'];
53
            $path = 'sources';
54 View Code Duplication
        } elseif ($this['account']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
            $base = Account::classUrl();
56
            $parent = $this['account'];
57
            $path = 'external_accounts';
58
        } else {
59
            $msg = "Bank accounts cannot be accessed without a customer ID or account ID.";
60
            throw new Error\InvalidRequest($msg, null);
61
        }
62
        $parentExtn = urlencode(Util\Util::utf8($parent));
63
        $extn = urlencode(Util\Util::utf8($this['id']));
64
        return "$base/$parentExtn/$path/$extn";
65
    }
66
67
    /**
68
     * @param array|string $_id
69
     * @param array|string|null $_opts
70
     *
71
     * @throws \Stripe\Error\InvalidRequest
72
     */
73
    public static function retrieve($_id, $_opts = null)
0 ignored issues
show
Unused Code introduced by
The parameter $_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $_opts is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
        $msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
76
               "Retrieve a bank account using \$customer->sources->retrieve('bank_account_id') or " .
77
               "\$account->external_accounts->retrieve('bank_account_id') instead.";
78
        throw new Error\InvalidRequest($msg, null);
79
    }
80
81
    /**
82
     * @param string $_id
83
     * @param array|null $_params
84
     * @param array|string|null $_options
85
     *
86
     * @throws \Stripe\Error\InvalidRequest
87
     */
88 View Code Duplication
    public static function update($_id, $_params = null, $_options = null)
0 ignored issues
show
Unused Code introduced by
The parameter $_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $_params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $_options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $msg = "Bank accounts cannot be accessed without a customer ID or account ID. " .
91
               "Call save() on \$customer->sources->retrieve('bank_account_id') or " .
92
               "\$account->external_accounts->retrieve('bank_account_id') instead.";
93
        throw new Error\InvalidRequest($msg, null);
94
    }
95
96
   /**
97
     * @param array|null $params
98
     * @param array|string|null $options
99
     *
100
     * @return BankAccount The verified bank account.
101
     */
102
    public function verify($params = null, $options = null)
103
    {
104
        $url = $this->instanceUrl() . '/verify';
105
        list($response, $opts) = $this->_request('post', $url, $params, $options);
0 ignored issues
show
Bug introduced by
It seems like $params can also be of type null; however, Stripe\ApiOperations\Request::_request() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
106
        $this->refreshFrom($response, $opts);
107
        return $this;
108
    }
109
}
110