User::apiKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace App\LaravelRestCms\User;
2
3
use App\LaravelRestCms\BaseModel;
4
5
class User extends BaseModel {
6
7
	public static $searchCols = ['first_name', 'last_name', 'email', 'username'];
8
9
	/**
10
	 * The database table used by the model.
11
	 *
12
	 * @var string
13
	 */
14
	protected $table = 'users';
15
16
	/**
17
	 * The attributes that are mass assignable.
18
	 *
19
	 * @var array
20
	 */
21
	protected $fillable = ['first_name', 'last_name', 'email', 'username'];
22
23
	/**
24
	 * The attributes excluded from the model's JSON form.
25
	 *
26
	 * @var array
27
	 */
28
	protected $hidden = [];
29
30
	/**
31
	 * Rules to validate when creating a model
32
	 * 
33
	* @var array
34
	 */
35
	protected static $createRules = [	
36
		'first_name' => 'required',
37
		'last_name' => 'required',
38
		'email' => 'required|email|unique:users',
39
		'username' => 'required|unique:users',
40
		'password' => 'required',
41
		//'created_by' => 'integer',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
42
		//'updated_by' => 'integer',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
43
	];
44
45
	/**
46
	 * Valiadate a user's login
47
	 * 
48
	 * @param  string $username 
49
	 * @param  string $password 
50
	 * @return \App\LaravelRestCms\BaseModel
51
	 */
52
	public function authenticate($username, $password)
53
	{
54
		return $this->where('username', $username)->where('password', $password)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\LaravelRestCms\User\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
55
	}
56
57
	/**
58
	 * Relationship to the api_key table
59
	 * 
60
	 * @codeCoverageIgnore
61
	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
62
	 */
63
	public function apiKey()
64
	{
65
		return $this->hasOne(\App\LaravelRestCms\ApiKey\ApiKey::class, 'user_id');
66
	} 
67
68
}
69