Completed
Push — master ( 150fd1...9bb841 )
by Mahmoud
06:22
created

GetUserSocialProfileTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 3
1
<?php
2
3
namespace App\Containers\SocialAuth\Tasks;
4
5
use App\Containers\SocialAuth\Exceptions\MissingTokenException;
6
use App\Containers\SocialAuth\Extra\SocialProvider;
7
use Laravel\Socialite\Facades\Socialite;
8
9
/**
10
 * Class GetUserSocialProfileTask.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class GetUserSocialProfileTask
15
{
16
17
    /**
18
     * @param      $provider
19
     * @param null $request
0 ignored issues
show
Documentation introduced by
There is no parameter named $request. Did you maybe mean $requestData?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
20
     *
21
     * @return  mixed
22
     */
23
    public function run($provider, array $requestData = null)
24
    {
25
26
        if ($provider == SocialProvider::FACEBOOK) {
27
            $user = Socialite::driver($provider)->userFromToken($requestData['access_token']);
28
        } elseif ($provider == SocialProvider::TWITTER) {
29
            // TODO: I have not yet submitted this PR to Socialite so the function `userFromTokenAndSecret` does not exist in the package
30
            $user = Socialite::driver($provider)->userFromTokenAndSecret($requestData['oauth_token'],
31
                $requestData['oauth_token_secret']);
32
33
            dd($user);
34
        }
35
36
        return $user;
0 ignored issues
show
Bug introduced by
The variable $user does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
37
    }
38
39
}
40