Completed
Push — master ( 5b70eb...51a683 )
by Brian
21:27 queued 11:30
created

AbstractProvider::parseExpiresIn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SocialiteProviders\Manager\OAuth2;
4
5
use Illuminate\Support\Arr;
6
use Laravel\Socialite\Two\InvalidStateException;
7
use SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface;
8
use SocialiteProviders\Manager\SocialiteWasCalled;
9
use SocialiteProviders\Manager\ConfigTrait;
10
use Laravel\Socialite\Two\AbstractProvider as BaseProvider;
11
12
abstract class AbstractProvider extends BaseProvider implements ProviderInterface
13
{
14
    use ConfigTrait;
15
16
    /**
17
     * @var array
18 1
     */
19
    protected $credentialsResponseBody;
20 1
21
    public static function serviceContainerKey($providerName)
22
    {
23 7
        return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName;
24
    }
25 7
26
    /**
27
     * @return \SocialiteProviders\Manager\OAuth2\User
28
     */
29
    public function user()
30
    {
31
        if ($this->hasInvalidState()) {
32
            throw new InvalidStateException();
33 1
        }
34
35 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...
36 1
37 1
        $user = $this->mapUserToObject($this->getUserByToken(
38 1
            $token = $this->parseAccessToken($response)
39
        ));
40 1
41
        $this->credentialsResponseBody = $response;
42
43
        if ($user instanceof User) {
44
            return $user->setAccessTokenResponseBody($this->credentialsResponseBody);
45
        }
46 5
47
        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...
48 5
                    ->setRefreshToken($this->parseRefreshToken($response))
49 2
                    ->setExpiresIn($this->parseExpiresIn($response));
50
    }
51
52 3
    /**
53 3
     * Get the access token from the token response body.
54 3
     *
55
     * @param string $body
56 3
     *
57
     * @return string
58 3
     */
59 3
    protected function parseAccessToken($body)
60
    {
61
        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...
62
    }
63
64
    /**
65
     * Get the refresh token from the token response body.
66
     *
67
     * @param string $body
68
     *
69
     * @return string
70
     */
71
    protected function parseRefreshToken($body)
72 3
    {
73
        return Arr::get($body, 'refresh_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...
74 3
    }
75
76 3
    /**
77 3
     * Get the expires in from the token response body.
78 3
     *
79 3
     * @param string $body
80
     *
81 3
     * @return string
82
     */
83 3
    protected function parseExpiresIn($body)
84
    {
85
        return Arr::get($body, 'expires_in');
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...
86
    }
87
}
88