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

TrackTrafficAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

1 Method

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