Completed
Push — master ( 1416f7...f9fc2d )
by Miguel
14:36 queued 07:03
created

src/OAuth2/AbstractProvider.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SocialiteProviders\Manager\OAuth2;
4
5
use Illuminate\Support\Arr;
6
use Laravel\Socialite\Two\AbstractProvider as BaseProvider;
7
use Laravel\Socialite\Two\InvalidStateException;
8
use SocialiteProviders\Manager\ConfigTrait;
9
use SocialiteProviders\Manager\Contracts\OAuth2\ProviderInterface;
10
use SocialiteProviders\Manager\SocialiteWasCalled;
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
    /**
22
     * @param string $providerName
23 7
     *
24
     * @return string
25 7
     */
26
    public static function serviceContainerKey($providerName)
27
    {
28
        return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName;
29
    }
30
31
    /**
32
     * @return \SocialiteProviders\Manager\OAuth2\User
33 1
     */
34
    public function user()
35 1
    {
36 1
        if ($this->hasInvalidState()) {
37 1
            throw new InvalidStateException();
38 1
        }
39
40 1
        $response = $this->getAccessTokenResponse($this->getCode());
0 ignored issues
show
It seems like $this->getCode() targeting Laravel\Socialite\Two\AbstractProvider::getCode() can also be of type array or null; however, Laravel\Socialite\Two\Ab...etAccessTokenResponse() does only seem to accept string, 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...
41
        $this->credentialsResponseBody = $response;
42
43
        $user = $this->mapUserToObject($this->getUserByToken(
44
            $token = $this->parseAccessToken($response)
0 ignored issues
show
$response is of type array, but the function expects a string.

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...
45
        ));
46 5
47
        if ($user instanceof User) {
48 5
            $user->setAccessTokenResponseBody($this->credentialsResponseBody);
49 2
        }
50
51
        return $user->setToken($token)
52 3
                    ->setRefreshToken($this->parseRefreshToken($response))
0 ignored issues
show
$response is of type array, but the function expects a string.

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...
53 3
                    ->setExpiresIn($this->parseExpiresIn($response));
0 ignored issues
show
$response is of type array, but the function expects a string.

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...
54 3
    }
55
56 3
    /**
57
     * Get the access token from the token response body.
58 3
     *
59 3
     * @param string $body
60
     *
61
     * @return string
62
     */
63
    protected function parseAccessToken($body)
64
    {
65
        return Arr::get($body, 'access_token');
0 ignored issues
show
$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...
66
    }
67
68
    /**
69
     * Get the refresh token from the token response body.
70
     *
71
     * @param string $body
72 3
     *
73
     * @return string
74 3
     */
75
    protected function parseRefreshToken($body)
76 3
    {
77 3
        return Arr::get($body, 'refresh_token');
0 ignored issues
show
$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...
78 3
    }
79 3
80
    /**
81 3
     * Get the expires in from the token response body.
82
     *
83 3
     * @param string $body
84
     *
85
     * @return string
86
     */
87
    protected function parseExpiresIn($body)
88
    {
89
        return Arr::get($body, 'expires_in');
0 ignored issues
show
$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...
90
    }
91
}
92