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

Completed
Pull Request — development (#48)
by José
04:01
created

AuthenticateController::userInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 2
eloc 15
nc 2
nop 0
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
14
class AuthenticateController extends Controller
15
{
16
      /**
17
       * Authenticate the user
18
       *
19
       * @param Request $request
20
       * @return \Illuminate\Http\JsonResponse
21
       */
22 2
    public function authenticate(Request $request)
23
    {
24
        // grab credentials from the request
25 2
        $credentials = $request->only('email', 'password');
26
27
        try {
28
            // attempt to verify the credentials and create a token for the user
29 2
            if (!$token = JWTAuth::attempt($credentials)) {
30 1
                return response()->json([ 'error' => 'invalid_credentials' ], 401);
31
            }
32
        } catch (JWTException $e) {
33
            // something went wrong whilst attempting to encode the token
34
            return response()->json([ 'error' => 'could_not_create_token' ], 500);
35
        }
36
37
        // all good so return the token
38 1
        return response()->json(
39
            [
40 1
              'access_token' => $token,
41 1
              'token_type' => 'Bearer'
42 1
            ], 200
43
        );
44
    }
45
46
    /**
47
     * Register a new User
48
     *
49
     * @param RegisterUserRequest $request
50
     * @return \Illuminate\Http\JsonResponse
51
     */
52 1
    public function register(RegisterUserRequest $request)
53
    {
54 1
        $user = User::create(
55
            [
56 1
            'first_name' => $request->first_name,
0 ignored issues
show
Documentation introduced by
The property first_name does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
57 1
            'last_name' => $request->last_name,
0 ignored issues
show
Documentation introduced by
The property last_name does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
58 1
            'email' => $request->email,
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
59 1
            'username' => $request->username,
0 ignored issues
show
Documentation introduced by
The property username does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60 1
            'phone' => $request->phone,
0 ignored issues
show
Documentation introduced by
The property phone does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61 1
            'bio' => $request->bio,
0 ignored issues
show
Documentation introduced by
The property bio does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62 1
            'blood_type_id' => $request->blood_type_id,
0 ignored issues
show
Documentation introduced by
The property blood_type_id does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63 1
            'birthdate' => $request->birthdate,
0 ignored issues
show
Documentation introduced by
The property birthdate does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64 1
            'password' => bcrypt($request->password),
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<DoeSangue\Http\Re...ts\RegisterUserRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
            ]
66
        );
67
68
        // Send mail to user
69 1
        Mail::to($user->email)->send(new UserCreated($user));
70
71
72
73 1
        $token = JWTAuth::attempt($request->only('email', 'password'));
74
75
        // all good so return the token
76 1
        return response()->json(
77
            [
78 1
            'access_token' => $token,
79 1
            'token_type' => 'Bearer'
80 1
            ], 201
81
        );
82
    }
83
84
    /**
85
     * Invalidate and log out the user
86
     *
87
     * @return void
88
     *
89
     */
90
    public function logout()
91
    {
92
        //
93
    }
94
95
}
96