Passed
Push — master ( 959235...00fed1 )
by Stephen
12:04
created

TrackTrafficAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 31
rs 10
c 3
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A execute() 0 9 2
1
<?php
2
3
namespace Sfneal\Tracking\Actions;
4
5
use Illuminate\Support\Facades\Log;
6
use Sfneal\Actions\Action;
7
use Sfneal\Helpers\Arrays\ArrayHelpers;
8
use Sfneal\Tracking\Models\TrackTraffic;
9
10
class TrackTrafficAction extends Action
11
{
12
    /**
13
     * @var array
14
     */
15
    private $tracking;
16
17
    /**
18
     * TrackTrafficAction constructor.
19
     *
20
     * @param array $tracking
21
     */
22
    public function __construct(array $tracking)
23
    {
24
        $this->tracking = (new ArrayHelpers($tracking))->arrayFlattenKeys();
25
    }
26
27
    /**
28
     * Retrieve tracking data and then do something with it.
29
     *
30
     * @return void
31
     */
32
    public function execute()
33
    {;
34
        // Log traffic data to DB
35
        TrackTraffic::query()->create($this->tracking);
36
37
        // Log JSON encoded activity to local log file
38
        // todo: add to config
39
        if (env('TRACK_TRAFFIC_LOGGING', false) == true) {
40
            Log::channel('traffic')->info(json_encode($this->tracking));
41
        }
42
    }
43
}
44