Completed
Push — master ( ec2990...7a5f39 )
by ARCANEDEV
07:59
created

CookieTracker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 38
ccs 3
cts 9
cp 0.3333
rs 10

2 Methods

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