StripeOAuth::deauthorize()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.0582

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 8
nop 2
dl 0
loc 20
ccs 11
cts 13
cp 0.8462
crap 4.0582
rs 9.2
c 0
b 0
f 0
1
<?php namespace Arcanedev\Stripe;
2
3
/**
4
 * Class     StripeOAuth
5
 *
6
 * @package  Arcanedev\Stripe
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
abstract class StripeOAuth
10
{
11
    /* -----------------------------------------------------------------
12
     |  Main Methods
13
     | -----------------------------------------------------------------
14
     */
15
16
    /**
17
     * Generates a URL to Stripe's OAuth form.
18
     *
19
     * @param  array|null  $params
20
     * @param  array|null  $options
21
     *
22
     * @return string
23
     */
24 2
    public static function authorizeUrl($params = null, $options = null)
25
    {
26 2
        if ( ! $params)
27
            $params = [];
28
29 2
        $params['client_id'] = self::getClientId($params);
30
31 2
        if ( ! array_key_exists('response_type', $params))
32 2
            $params['response_type'] = 'code';
33
34 2
        $base = ($options && array_key_exists('connect_base', $options))
35
            ? $options['connect_base']
36 2
            : Stripe::$connectBase;
37
38 2
        return $base.'/oauth/authorize?'.str_url_queries($params);
39
    }
40
41
    /**
42
     * Use an authorization code to connect an account to your platform and fetch the user's credentials.
43
     *
44
     * @param  array|null  $params
45
     * @param  array|null  $options
46
     *
47
     * @return \Arcanedev\Stripe\StripeObject
48
     */
49 6
    public static function token($params = null, $options = null)
50
    {
51 6
        $base = ($options && array_key_exists('connect_base', $options))
52
            ? $options['connect_base']
53 6
            : Stripe::$connectBase;
54
55
        /** @var  \Arcanedev\Stripe\Http\Response  $response */
56 6
        list($response, $apiKey) = Http\Requestor::make(null, $base)->request(
0 ignored issues
show
Unused Code introduced by
The assignment to $apiKey is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
57 6
            'post',
58 6
            '/oauth/token',
59 6
            $params,
60 6
            null
61
        );
62
63 2
        return Utilities\Util::convertToStripeObject($response->getJson(), $options);
0 ignored issues
show
Bug introduced by
It seems like $response->getJson() targeting Arcanedev\Stripe\Http\Response::getJson() can also be of type null; however, Arcanedev\Stripe\Utiliti...convertToStripeObject() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug introduced by
It seems like $options defined by parameter $options on line 49 can also be of type null; however, Arcanedev\Stripe\Utiliti...convertToStripeObject() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug Compatibility introduced by
The expression \Arcanedev\Stripe\Utilit...->getJson(), $options); of type Arcanedev\Stripe\StripeO...Stripe\Collection|array adds the type array to the return on line 63 which is incompatible with the return type documented by Arcanedev\Stripe\StripeOAuth::token of type Arcanedev\Stripe\StripeObject.
Loading history...
64
    }
65
66
    /**
67
     * Disconnects an account from your platform.
68
     *
69
     * @param  array|null  $params
70
     * @param  array|null  $options
71
     *
72
     * @return \Arcanedev\Stripe\StripeObject
73
     */
74 4
    public static function deauthorize($params = null, $options = null)
75
    {
76 4
        if ( ! $params)
77
            $params = [];
78
79 4
        $base = ($options && array_key_exists('connect_base', $options))
80
            ? $options['connect_base']
81 4
            : Stripe::$connectBase;
82
83 4
        $params['client_id'] = self::getClientId($params);
84
85 4
        list($response, $apiKey) = Http\Requestor::make(null, $base)->request(
0 ignored issues
show
Unused Code introduced by
The assignment to $apiKey is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
86 4
            'post',
87 4
            '/oauth/deauthorize',
88 4
            $params,
89 4
            null
90
        );
91
92 4
        return Utilities\Util::convertToStripeObject($response->getJson(), $options);
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 74 can also be of type null; however, Arcanedev\Stripe\Utiliti...convertToStripeObject() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug Compatibility introduced by
The expression \Arcanedev\Stripe\Utilit...->getJson(), $options); of type Arcanedev\Stripe\StripeO...Stripe\Collection|array adds the type array to the return on line 92 which is incompatible with the return type documented by Arcanedev\Stripe\StripeOAuth::deauthorize of type Arcanedev\Stripe\StripeObject.
Loading history...
93
    }
94
95
    /* -----------------------------------------------------------------
96
     |  Other Methods
97
     | -----------------------------------------------------------------
98
     */
99
100 6
    private static function getClientId($params = null)
101
    {
102 6
        $clientId = ($params && array_key_exists('client_id', $params)) ? $params['client_id'] : null;
103
104 6
        if ($clientId === null)
105 6
            $clientId = Stripe::getClientId();
106
107 6
        if ($clientId === null) {
108
            throw new Exceptions\AuthenticationException(
109
                'No client_id provided.  (HINT: set your client_id using '
110
                . '"Stripe::setClientId(<CLIENT-ID>)".  You can find your client_ids '
111
                . 'in your Stripe dashboard at '
112
                . 'https://dashboard.stripe.com/account/applications/settings, '
113
                . 'after registering your account as a platform. See '
114
                . 'https://stripe.com/docs/connect/standard-accounts for details, '
115
                . 'or email [email protected] if you have any questions.'
116
            );
117
        }
118
119 6
        return $clientId;
120
    }
121
}
122