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 Failed
Branch development (3784af)
by José
05:42 queued 02:43
created

AuthenticateController::authenticate()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 3
eloc 10
nc 4
nop 1
1
<?php
2
3
namespace DoeSangue\Http\Controllers\Auth;
4
5
use JWTAuth;
6
use Tymon\JWTAuth\Exceptions\JWTException;
7
use DoeSangue\Http\Controllers\Controller;
8
use Illuminate\Http\Request;
9
use DoeSangue\Http\Requests\RegisterUserRequest;
10
use DoeSangue\Mail\UserCreated;
11
use Illuminate\Support\Facades\Mail;
12
use DoeSangue\Models\User;
13
use DoeSangue\Models\Donor;
14
15
class AuthenticateController extends Controller
16
{
17
    public function authenticate(Request $request)
18
    {
19
        // grab credentials from the request
20
        $credentials = $request->only('email', 'password');
21
22
        try {
23
            // attempt to verify the credentials and create a token for the user
24
            if (!$token = JWTAuth::attempt($credentials)) {
25
                return response()->json([ 'error' => 'invalid_credentials' ], 401);
26
            }
27
        } catch (JWTException $e) {
28
            // something went wrong whilst attempting to encode the token
29
            return response()->json([ 'error' => 'could_not_create_token' ], 500);
30
        }
31
32
        // all good so return the token
33
        return response()->json(
34
            [
35
             "data" {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal data does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
36
                'access_token' => $token,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_DOUBLE_ARROW
Loading history...
37
                'token_type' => 'Bearer'
38
             }
39
            ]
40
        );
41
    }
42
43
    // Register a new user
44
    public function register(RegisterUserRequest $request)
45
    {
46
        $user = User::create(
47
            [
48
            'first_name' => $request->first_name,
49
            'last_name' => $request->last_name,
50
            'email' => $request->email,
51
            // create the username based on first_name and last_name
52
            // if not provided
53
            /*$userName = trim(strtolower($request->first_name.'-'.$request->last_name)),
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
            'username' => $userName,*/
55
            'username' => $request->username,
56
            'phone' => $request->phone,
57
            'bio' => $request->bio,
58
            'birthdate' => $request->birthdate,
59
            'password' => bcrypt($request->password),
60
            ]
61
        );
62
63
        if ($user) {
64
            $donor = new Donor();
65
            $donor->user_id = $user->id;
66
            $donor->blood_type_id = null;
67
            $donor->save();
68
        }
69
70
        // Send mail to user
71
        Mail::to($user->email)->send(new UserCreated($user));
72
73
74
75
        $token = JWTAuth::attempt($request->only('email', 'password'));
76
77
        // all good so return the token
78
        return response()->json(
79
            [
80
            'access_token' => $token,
81
            'token_type' => 'Bearer'
82
            ], 201
83
        );
84
    }
85
86
    /**
87
     * Invalidate and log out the user
88
     */
89
    public function logout()
90
    {
91
        //
92
    }
93
94
    public function userInfo()
95
    {
96
        $user = JWTAuth::parseToken()->authenticate();
97
98
        // If the token is invalid
99
        if (! $user) {
100
            return response()->json(['invalid_user'], 401);
101
        }
102
103
        return response()->json(
104
            [
105
              'first_name' => $user->first_name,
106
              'last_name' => $user->last_name,
107
            //   'email' => $user->email,
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
108
              'username' => $user->username
109
            ], 200
110
        );
111
    }
112
}
113