RegistersUsers   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 4
c 5
b 2
f 0
lcom 1
cbo 2
dl 0
loc 36
ccs 0
cts 17
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A customClaims() 0 4 2
A postRegister() 0 16 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Claudio Cardinale <[email protected]>
5
 * Date: 18/11/15
6
 * Time: 16.23
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 */
19
20
namespace Tymon\JWTAuth\Support\auth;
21
22
use Illuminate\Http\JsonResponse;
23
use Illuminate\Http\Request;
24
use Tymon\JWTAuth\Facades\JWTAuth;
25
26
/**
27
 * Class RegistersUsers
28
 * @package Tymon\JWTAuth\Support\auth
29
 * @author Claudio Cardinale <[email protected]>
30
 * @copyright 2015 Claudio Cardinale
31
 * @version 1.0.0
32
 */
33
trait RegistersUsers
34
{
35
    /**
36
     * Handle a registration request for the application.
37
     *
38
     * @param  \Illuminate\Http\Request  $request
39
     * @return \Illuminate\Http\Response
40
     */
41
    public function postRegister(Request $request)
42
    {
43
        $validator = $this->validator($request->all());
0 ignored issues
show
Bug introduced by
It seems like validator() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
44
45
        if ($validator->fails()) {
46
            $this->throwValidationException(
0 ignored issues
show
Bug introduced by
It seems like throwValidationException() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
47
                $request, $validator
48
            );
49
        }
50
51
        $token = JWTAuth::fromUser($this->create($request->all()), $this->customClaims());
0 ignored issues
show
Bug introduced by
It seems like create() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52
53
        $response = new JsonResponse(['token' => $token], 200);
54
        $response->header('Authorization', 'Bearer ' . $token);
55
        return $response;
56
    }
57
58
    /**
59
     * Get the custom claims
60
     *
61
     * @return string
62
     */
63
    public function customClaims()
64
    {
65
        return property_exists($this, 'custom') ? $this->custom : [];
0 ignored issues
show
Bug introduced by
The property custom does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
    }
67
68
}