Completed
Push — master ( 20d915...79eb1e )
by Mahmoud
03:50
created

TokenTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A injectToken() 0 6 1
A withToken() 0 4 1
1
<?php
2
3
namespace App\Containers\Authentication\Traits;
4
5
use App\Containers\Authentication\Tasks\ApiGenerateTokenFromObjectTask;
6
use Illuminate\Support\Facades\App;
7
8
/**
9
 * Class TokenTrait.
10
 *
11
 * To be `used` by the `User` Model.
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
trait TokenTrait
16
{
17
18
    /**
19
     * inject a token in the user model itself.
20
     * if no token provided generate token first.
21
     *
22
     * @param null $token
23
     *
24
     * @return $this
25
     */
26
    public function injectToken($token)
27
    {
28
        $this->token = $token;
0 ignored issues
show
Bug introduced by
The property token 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...
29
30
        return $this;
31
    }
32
33
    /**
34
     * When calling this function, the token will be added on the model.
35
     *
36
     * @return  $this
37
     */
38
    public function withToken()
39
    {
40
        return $this->injectToken((App::make(ApiGenerateTokenFromObjectTask::class))->run($this));
41
    }
42
}
43