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

TokenTrait::injectToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 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