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

InvitationRequestsController::createInvitation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2.1481

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 12
cts 18
cp 0.6667
rs 9.456
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.1481
1
<?php
2
3
namespace DoeSangue\Http\Controllers\Auth\V1;
4
5
use Illuminate\Http\Request;
6
use DoeSangue\Http\Controllers\Controller;
7
use DoeSangue\Http\Requests\UserInvitationRequest;
8
use Hash,
9
    DB;
10
11
class InvitationRequestsController extends Controller
12
{
13
    /**
14
     * Create an invite when user requests from API.
15
     *
16
     * @param UserInvitationRequest $request
17
     * @return \Illuminate\Http\JsonResponse
18
     */
19 1
    public function createInvitation(Request $request)
20
    {
21
22 1
        $guestExist = DB::table('invitation_requests')
23 1
                      ->where('guest_email', $request['guest_email'])->first();
24
25 1
        if (!$guestExist) {
26
            $guest = [
27 1
                'first_name' => $request->first_name,
28 1
                'last_name' => $request->last_name,
29 1
                'guest_email' => $request->guest_email,
30 1
                'country_id' => $request->country_id,
31 1
                'token' => Hash::make(str_random(60)),
32 1
                'created_at' => \Carbon\Carbon::now(),
33 1
                'updated_at' => \Carbon\Carbon::now()
34
            ];
35
36 1
            DB::table('invitation_requests')->insert($guest);
37
38
            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...
39
                'message' => 'Urrah! You have been invited. Check you email for more information.'
40
            ], 201);
41
        } else {
42
            return response()->json([
43
                'message' => 'Oops. Looks like you have been invited already. But don\'t scary, we will send you again!'
44
            ], 200);
45
        }
46
47
    }
48
49
    /**
50
     * Check if User was invited before.
51
     *
52
     * @param Request $data
53
     * @return void
54
     */
55
    public function checkInvitation(Request $data)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {}
57
}
58