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

InvitationRequestsController::createInvitation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace GiveBlood\Units\Authentication\Http\Controllers\Auth;
4
5
use Illuminate\Http\Request;
6
use GiveBlood\Support\Http\Controllers\Controller;
7
use GiveBlood\Support\Http\Controllers\UserInvitationRequest;
8
use Hash, DB;
9
10
class InvitationRequestsController extends Controller
11
{
12
    /**
13
     * Create an invite when user requests from API.
14
     *
15
     * @param  UserInvitationRequest $request
16
     * @return \Illuminate\Http\JsonResponse
17
     */
18
    public function createInvitation(Request $request)
19
    {
20
21
        $guestExist = DB::table('invitation_requests')
22
            ->where('guest_email', $request['guest_email'])->first();
23
24
        if (!$guestExist) {
25
            $guest = [
26
                'first_name' => $request->first_name,
27
                'last_name' => $request->last_name,
28
                'guest_email' => $request->guest_email,
29
                'country_id' => $request->country_id,
30
                'token' => Hash::make(str_random(60)),
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated with message: Str::random() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
31
                'created_at' => \Carbon\Carbon::now(),
32
                'updated_at' => \Carbon\Carbon::now()
33
            ];
34
35
            DB::table('invitation_requests')->insert($guest);
36
37
            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...
38
                [
39
                'message' => 'Urrah! You have been invited. Check you email for more information.'
40
                ], 201
41
            );
42
        } else {
43
            return response()->json(
44
                [
45
                'message' => 'Oops. Looks like you have been invited already. But don\'t scary, we will send you again!'
46
                ], 200
47
            );
48
        }
49
50
    }
51
52
    /**
53
     * Check if User was invited before.
54
     *
55
     * @param  Request $data
56
     * @return void
57
     */
58
    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...
59
    {
60
    }
61
}
62