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

TrackActionAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 7 1
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