GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5701b0...88717a )
by Brian
02:03
created

MakeProviderCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 112
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B fire() 0 40 4
A getArguments() 0 6 1
A getOptions() 0 13 1
A addToComposer() 0 9 1
1
<?php
2
3
namespace SocialiteProviders\Generators\Console;
4
5
use Illuminate\Console\Command;
6
use SocialiteProviders\Generators\Compilers\Compiler;
7
use SocialiteProviders\Generators\Compilers\OAuth1Compiler;
8
use SocialiteProviders\Generators\Compilers\OAuth2Compiler;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputOption;
11
12
class MakeProviderCommand extends Command
13
{
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'make:socialite';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new OAuth1 Provider.';
27
28
    /**
29
     * Create a new controller creator command instance.
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     */
39
    public function fire()
40
    {
41
        $data = [
42
            'name'            => $this->argument('name'),
43
            'authorName'      => $this->option('author'),
44
            'authorMail'      => $this->option('email'),
45
            'oauthVersion'    => $this->option('spec'),
46
            'scopes'          => $this->option('scopes'),
47
            'requestTokenUrl' => $this->option('request_token_url'),
48
            'authorizeUrl'    => $this->option('authorize_url'),
49
            'accessTokenUrl'  => $this->option('access_token_url'),
50
            'userDetailsUrl'  => $this->option('user_details_url'),
51
        ];
52
53
        switch ($this->option('spec')) {
54
            case 'oauth1':
55
                $compiler = new OAuth1Compiler($data);
56
            break;
57
58
            case 'oauth2':
59
                $compiler = new OAuth2Compiler($data);
60
            break;
61
62
            default:
63
                return $this->error('Neither OAuth1 nor OAuth2 was specified.');
64
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
65
        }
66
67
        $compiler->composer();
68
        $compiler->extendSocialite();
69
        $compiler->provider();
70
71
        if ($this->option('spec') === 'oauth1') {
72
            $compiler->server();
0 ignored issues
show
Bug introduced by
The method server does only exist in SocialiteProviders\Gener...ompilers\OAuth1Compiler, but not in SocialiteProviders\Gener...ompilers\OAuth2Compiler.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
        }
74
75
        $this->addToComposer($compiler);
76
77
        $this->info('Provider generated. Run "composer dumpautoload" and "composer require socialiteproviders/manager" to get started.');
78
    }
79
80
    /**
81
     * Get the console command arguments.
82
     *
83
     * @return array
84
     */
85
    protected function getArguments()
86
    {
87
        return [
88
            ['name', InputArgument::REQUIRED, 'Name of the provider.'],
89
        ];
90
    }
91
92
    /**
93
     * Get the console command options.
94
     *
95
     * @return array
96
     */
97
    protected function getOptions()
98
    {
99
        return [
100
            ['spec', null, InputOption::VALUE_REQUIRED, 'The OAuth version that should be used.'],
101
            ['author', null, InputOption::VALUE_REQUIRED, 'The name of the author.'],
102
            ['email', null, InputOption::VALUE_REQUIRED, 'The email of the author.'],
103
            ['scopes', null, InputOption::VALUE_OPTIONAL, 'The scopes to be requested.'],
104
            ['request_token_url', null, InputOption::VALUE_OPTIONAL, 'The Request-Token-Endpoint URL.'],
105
            ['authorize_url', null, InputOption::VALUE_OPTIONAL, 'The Authorization-Endpoint URL.'],
106
            ['access_token_url', null, InputOption::VALUE_OPTIONAL, 'The Access-Token-Endpoint URL.'],
107
            ['user_details_url', null, InputOption::VALUE_OPTIONAL, 'The User-Details-Endpoint URL.'],
108
        ];
109
    }
110
111
    /**
112
     * @param \SocialiteProviders\Generators\Compilers\Compiler $compiler
113
     */
114
    private function addToComposer(Compiler $compiler)
115
    {
116
        $contents = json_decode(file_get_contents($filename = base_path('composer.json')), true);
117
118
        $providerName = $compiler->getContext()->nameStudlyCase();
119
        $contents['autoload']['psr-4']["SocialiteProviders\\$providerName"] = "SocialiteProviders/$providerName/src/";
120
121
        file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
122
    }
123
}
124