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

TrackTrafficAction::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 9
rs 10
c 2
b 0
f 0
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