Passed
Push — master ( 6b0e6b...43789e )
by Stephen
03:30
created

TrackActivityAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 6
dl 0
loc 14
rs 10
1
<?php
2
3
namespace Sfneal\Tracking\Actions;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sfneal\Actions\AbstractAction;
7
use Sfneal\Tracking\Models\TrackActivity;
8
9
class TrackActivityAction extends AbstractAction
10
{
11
    public $model;
12
    public $request_token;
13
    public $user_id;
14
    public $route;
15
    public $model_changes;
16
    public $description;
17
18
    /**
19
     * Track a user's action.
20
     *
21
     * @param Model       $model
22
     * @param string|null $request_token
23
     * @param int         $user_id
24
     * @param string|null $route
25
     * @param array       $model_changes
26
     * @param string|null $description
27
     */
28
    public function __construct(
29
        Model $model,
30
        string $request_token = null,
31
        int $user_id = 0,
32
        string $route = null,
33
        array $model_changes = [],
34
        string $description = null
35
    ) {
36
        $this->model = $model;
37
        $this->request_token = $request_token;
38
        $this->user_id = $user_id;
39
        $this->route = $route;
40
        $this->model_changes = $model_changes;
41
        $this->description = $description;
42
    }
43
44
    /**
45
     * Track a user's activity/actions.
46
     *
47
     * @return void
48
     */
49
    public function execute()
50
    {
51
        TrackActivity::query()->create([
52
            'user_id'       => $this->user_id,
53
            'route'         => $this->route,
54
            'description'   => $this->description,
55
            'model_table'   => $this->model->getTable(),
56
            'model_key'     => $this->model->getKey(),
57
            'model_changes' => $this->model_changes,
58
            'request_token' => $this->request_token,
59
        ]);
60
    }
61
}
62