Completed
Push — master ( 43f209...d4d820 )
by Brian
06:44
created

AbstractProvider::getAccessToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 13
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2.0625

1 Method

Rating   Name   Duplication   Size   Complexity  
A AbstractProvider::parseAccessToken() 0 4 1
1
<?php
2
3
namespace SocialiteProviders\Manager\OAuth2;
4
5
use Illuminate\Support\Arr;
6
use GuzzleHttp\ClientInterface;
7
use Laravel\Socialite\Two\InvalidStateException;
8
use SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface;
9
use SocialiteProviders\Manager\SocialiteWasCalled;
10
use SocialiteProviders\Manager\ConfigTrait;
11
use Laravel\Socialite\Two\AbstractProvider as BaseProvider;
12
13
abstract class AbstractProvider extends BaseProvider implements ProviderInterface
14
{
15
    use ConfigTrait;
16
17
    /**
18 1
     * @var array
19
     */
20 1
    protected $credentialsResponseBody;
21
22
    public static function serviceContainerKey($providerName)
23 7
    {
24
        return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName;
25 7
    }
26
27
    /**
28
     * @return \SocialiteProviders\Manager\OAuth2\User
29
     */
30
    public function user()
31
    {
32
        if ($this->hasInvalidState()) {
33 1
            throw new InvalidStateException();
34
        }
35 1
36 1
        $response = $this->getAccessTokenResponse($this->getCode());
0 ignored issues
show
Bug introduced by
The method getAccessTokenResponse() does not exist on SocialiteProviders\Manager\OAuth2\AbstractProvider. Did you maybe mean getAccessToken()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37 1
38 1
        $user = $this->mapUserToObject($this->getUserByToken(
39
            $token = $this->parseAccessToken($response)
40 1
        ));
41
42
        $this->credentialsResponseBody = $response;
43
44
        if ($user instanceof User) {
45
            return $user->setAccessTokenResponseBody($this->credentialsResponseBody);
46 5
        }
47
48 5
        return $user->setToken($token)
0 ignored issues
show
Bug introduced by
The method setRefreshToken() does not seem to exist on object<Laravel\Socialite\Two\User>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49 2
                    ->setRefreshToken(Arr::get($response, 'refresh_token'))
50
                    ->setExpiresIn(Arr::get($response, 'expires_in'));
51
    }
52 3
53 3
    /**
54 3
     * Get the access token from the token response body.
55
     *
56 3
     * @param string $body
57
     *
58 3
     * @return string
59 3
     */
60
    protected function parseAccessToken($body)
61
    {
62
        return Arr::get($body, 'access_token');
0 ignored issues
show
Documentation introduced by
$body is of type string, but the function expects a object<ArrayAccess>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
    }
64
}
65