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

TrackTrafficAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
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