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

InvitesController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 33
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 17 1
A show() 0 6 1
1
<?php
2
3
namespace DoeSangue\Http\Controllers\API\V1;
4
5
use Illuminate\Http\Request;
6
use DoeSangue\Http\Controllers\Controller;
7
use Tymon\JWTAuth\Facades\JWTAuth;
8
use DoeSangue\Repositories\Invites;
9
use DoeSangue\Models\Invite;
10
use Hash;
11
12
class InvitesController extends Controller
13
{
14
    public function __construct()
15
    {
16
        $this->middleware('jwt.auth', [ 'except' => [ 'invite' ] ]);
17
    }
18
19
    public function create(Request $request)
20
    {
21
        // Determines the user/owner of invite.
22
        $user = JWTAuth::parseToken()->authenticate();
23
24
        $invite = new Invite();
25
        $invite->invite_code = Hash::make($request[ 'invite_code' ]);
26
        $invite->user_id = $user->id;
27
        $invite->save();
28
29
        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...
30
            [
31
            'status_code' => 201,
32
            'message' => 'Invite created!'
33
            ], 201
34
        );
35
    }
36
37
    public function show($id)
38
    {
39
        $invite = Invite::find($id);
40
41
        return response()->json($invite, 200);
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...
42
    }
43
44
}
45