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

TrackActionAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
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\TrackAction;
8
9
class TrackActionAction extends AbstractAction
10
{
11
    public $action;
12
    public $model;
13
    public $model_changes;
14
15
    /**
16
     * Track a user's action.
17
     *
18
     * @param string $action
19
     * @param Model  $model
20
     * @param array  $model_changes
21
     */
22
    public function __construct(string $action, Model $model, array $model_changes)
23
    {
24
        $this->action = $action;
25
        $this->model = $model;
26
        $this->model_changes = $model_changes;
27
    }
28
29
    /**
30
     * Track a user's activity/actions.
31
     *
32
     * @return void
33
     */
34
    public function execute()
35
    {
36
        TrackAction::query()->create([
37
            'action'        => $this->action,
38
            'model_table'   => $this->model->getTable(),
39
            'model_key'     => $this->model->getKey(),
40
            'model_changes' => $this->model_changes,
41
        ]);
42
    }
43
}
44