Completed
Push — master ( f76772...1672bb )
by ARCANEDEV
07:47
created

CookieTracker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 41
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A track() 0 10 2
1
<?php namespace Arcanedev\LaravelTracker\Trackers;
2
3
use Arcanedev\LaravelTracker\Contracts\Trackers\CookieTracker as CookieTrackerContract;
4
use Arcanedev\LaravelTracker\Models\Cookie;
5
use Illuminate\Contracts\Cookie\QueueingFactory as CookieJar;
6
use Ramsey\Uuid\Uuid;
7
8
/**
9
 * Class     CookieTracker
10
 *
11
 * @package  Arcanedev\LaravelTracker\Trackers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class CookieTracker implements CookieTrackerContract
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Properties
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
21
    /* ------------------------------------------------------------------------------------------------
22
     |  Constructor
23
     | ------------------------------------------------------------------------------------------------
24
     */
25
    /**
26
     * CookieTracker constructor.
27
     */
28 24
    public function __construct()
29
    {
30
        //
31 24
    }
32
33
    /* ------------------------------------------------------------------------------------------------
34
     |  Main Functions
35
     | ------------------------------------------------------------------------------------------------
36
     */
37
    /**
38
     * Track the cookie.
39
     *
40
     * @param  mixed  $cookie
41
     *
42
     * @return int
43
     */
44 6
    public function track($cookie)
45
    {
46 6
        if ( ! $cookie) {
47 6
            $cookie = (string) Uuid::uuid4();
48
49 6
            app(CookieJar::class)->queue(config('laravel-tracker.cookie.name'), $cookie, 0);
50 3
        }
51
52 6
        return Cookie::firstOrCreate(['uuid' => $cookie])->id;
53
    }
54
}
55