Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Test Setup Failed
Pull Request — development (#68)
by José
06:06
created

Api::userRoutes()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79

Duplication

Lines 24
Ratio 30.38 %

Importance

Changes 0
Metric Value
dl 24
loc 79
rs 8.4581
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace GiveBlood\Units\Authentication\Routes;
4
5
use GiveBlood\Support\Http\Routing\Router;
6
/**
7
 * Api class
8
 *
9
 * @category Api
10
 *
11
 * @package LinkaFaturas
12
 *
13
 * @author José Cage <[email protected]>
14
 *
15
 * @license proprietary https://mentedigital.xyz
16
 *
17
 * @link https://mentedigital.xyz
18
 */
19
class Api extends Router
20
{
21
    /*
22
    |--------------------------------------------------------------------------
23
    | API Routes
24
    |--------------------------------------------------------------------------
25
    |
26
    | Here is where you can register API routes for your application. These
27
    | routes are loaded by the RouteServiceProvider within a group which
28
    | is assigned the "api" middleware group. Enjoy building your API!
29
    |
30
    */
31
32
    protected function routes()
33
    {
34
        $this->homeRoutes();
35
        $this->authRoutes();
36
        $this->userRoutes();
37
        $this->campaignRoutes();
38
    }
39
40
    protected function homeRoutes()
41
    {
42
        $this->router->get(
43
            '/', function () {
44
                return response()->json([ 'message' => 'Hello World!']);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
45
            }
46
        );
47
48
        // Search campaigns and donors.
49
        $this->router->group(
50
            ['prefix' => 'search', 'namespace' => '\GiveBlood\Support\Http\Controllers'], function () {
51
                // Search campaigns
52
                $this->router->get('/', 'SearchController@search');
53
            }
54
        );
55
56
        $this->router->fallback(
57
            function () {
58
                return response()->json(
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

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...
59
                    [
60
                    'error' => 'Route cannot be found!'], 404
61
                );
62
            }
63
        );
64
65
    }
66
67
    protected function authRoutes()
68
    {
69
        // API Authentication routes
70
        // Create new Token
71
        $this->router->group(
72 View Code Duplication
            ['prefix' => 'v1', 'namespace' => '\GiveBlood\Units\Authentication\Http\Controllers\Auth'], function ($auth) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
                $auth->post('/auth/login', 'AuthenticateController@authenticate');
74
                $auth->get('/auth/logout', 'AuthenticateController@logout');
75
                $auth->post('/auth/register', 'AuthenticateController@register');
76
                $auth->group(
77
                    ['prefix' => 'password'], function ($password) {
78
                        $password->post('/recover', 'PasswordResetController@recover')->name('password.reset');
79
                        $password->post('/reset/{token}', 'PasswordResetController@reset');
80
                    }
81
                );
82
                // invitation routes
83
                $auth->group(
84
                    ['prefix' => 'invitation'], function ($invitation) {
85
                        $invitation->post('/', 'InvitationRequestsController@createInvitation');
86
                        $invitation->get('/check', 'InvitationRequestsController@checkInvation');
87
                    }
88
                );
89
            }
90
        );
91
92
        $this->router->group(
93 View Code Duplication
            ['prefix' => 'v1', 'namespace' => '\GiveBlood\Units\Authentication\Http\Controllers\Auth'], function ($auth) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
                $auth->post('/auth/login', 'AuthenticateController@authenticate');
95
                $auth->get('/auth/logout', 'AuthenticateController@logout');
96
                //        $auth->post('/auth/register', 'AuthenticateController@register');
97
                $auth->group(
98
                    ['prefix' => 'password'], function ($password) {
99
                        $password->post('/recover', 'PasswordResetController@recover')->name('password.reset');
100
                        $password->post('/reset/{token}', 'PasswordResetController@reset');
101
                    }
102
                );
103
                // invitation routes
104
                $auth->group(
105
                    ['prefix' => 'invitation'], function ($invitation) {
106
                        $invitation->post('/', 'InvitationRequestsController@createInvitation');
107
                        $invitation->get('/check', 'InvitationRequestsController@checkInvation');
108
                    }
109
                );
110
            }
111
        );
112
    }
113
114
    protected function userRoutes()
115
    {
116
        // Donors
117
        $this->router->group(
118
            ['namespace' => '\GiveBlood\Support\Http\Controllers', 'prefix' => 'donors'], function ($donor) {
119
                // Because all donor is a user
120
                // We will use UsersController instead
121
                // All donors
122
                $donor->get('/', 'UsersController@index');
123
                // show info about donor
124
                $donor->get('{donor}', 'UsersController@show');
125
126
                // Campaigns by donor
127
                $donor->get('{donor}/campaigns', 'UsersController@getCampaigns');
128
                $donor->get('{donor}/campaigns/{campaign}', 'UsersController@showCampaign');
129
            }
130
        );
131
        // Donors API
132
        $this->router->group(
133
            ['namespace' => '\GiveBlood\Support\Http\Controllers', 'prefix' => 'v1'], function () {
134
135
                // Routes related to logged in user
136
                $this->router->group(
137 View Code Duplication
                    ['prefix' => 'me', 'namespace' => 'User'], function ($user) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
                        // Get user information.
139
                        $user->get('/', 'AccountController@userInfo');
140
                        // Update User profile information.
141
                        $user->put('/', 'AccountController@updateProfile');
142
                        // User campigns
143
                        $user->group(
144
                            ['prefix' => 'campaigns'], function ($campaign) {
145
                                // Get all user Campaigns.
146
                                $campaign->get('/', 'CampaignController@index');
147
                                // Create Campaign
148
                                $campaign->post('/', 'CampaignController@store');
149
                                // Show complete info about campaign
150
                                $campaign->get('/{campaign}', 'CampaignController@show');
151
                                // Update campaign
152
                                $campaign->put('/{campaign}', 'CampaignController@update');
153
                                // Detele Campaign
154
                                $campaign->delete('/{campaign}', 'CampaignController@destroy');
155
                            }
156
                        );
157
158
                        // User donations
159
                        $user->get('/donations', 'DonationController@donations');
160
                    }
161
                );
162
163
                // Blood Banks
164
                $this->router->group(
165
                    ['prefix' => 'banks'], function ($bank) {
166
                        $bank->get('/', 'BankController@index');
167
                        $bank->get('/{bank}', 'BankController@show');
168
                    }
169
                );
170
171
                // BloodTypes
172
                $this->router->group(
173
                    ['prefix' => 'bloodtypes'], function () {
174
                        $this->router->get('/', 'BloodTypeController@index');
175
                    }
176
                );
177
                /*
178
                // Invites.
179
                Route::group(
180
                    ['prefix' => 'invites'], function ($invite) {
181
                        // Create a new invite.
182
                        $invite->post('/', 'InvitesController@create');
183
                        // Get a Invite details.
184
                        $invite->get('/{invite}', 'InvitesController@show');
185
                        // Delete a invite.
186
                        $invite->delete('/{invite}', 'InvitesController@destroy');
187
                    }
188
                );
189
                */
190
            }
191
        );
192
    }
193
194
    protected function campaignRoutes()
195
    {
196
        // Campaign
197
        $this->router->group(
198
            ['namespace' => '\GiveBlood\Support\Http\Controllers', 'prefix' => 'v1'], function () {
199
200
                $this->router->group(
201
                    ['prefix' => 'campaigns'], function ($campaign) {
202
                        //All Campaigns
203
                        $campaign->get('/', 'CampaignController@index');
204
                        // Campaign details
205
                        $campaign->get('{campaign}', 'CampaignController@show');
206
                        // Comments
207
                        $campaign->get('{campaign}/comments', 'CommentsController@index');
208
                        $campaign->post('{campaign}/comments', 'CommentsController@create');
209
                        $campaign->put('{campaign}/comments/{comment}', 'CommentsController@update');
210
                        $campaign->delete('{campaign}/comments/{comment}', 'CommentsController@destroy');
211
                    }
212
                );
213
            }
214
        );
215
216
    }
217
218
}
219