Completed
Pull Request — master (#2)
by ARCANEDEV
09:30
created

AbstractTracker::session()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\LaravelTracker\Trackers;
2
3
use Illuminate\Contracts\Foundation\Application;
4
5
/**
6
 * Class     AbstractTracker
7
 *
8
 * @package  Arcanedev\LaravelTracker\Trackers
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
abstract class AbstractTracker
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /** @var \Illuminate\Contracts\Foundation\Application */
18
    private $app;
19
20
    /* ------------------------------------------------------------------------------------------------
21
     |  Constructor
22
     | ------------------------------------------------------------------------------------------------
23
     */
24
    /**
25
     * AbstractTracker constructor.
26
     */
27 180
    public function __construct(Application $app)
28
    {
29 180
        $this->app = $app;
30 180
    }
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Common Functions
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Get the config instance.
38
     *
39
     * @return \Illuminate\Contracts\Config\Repository
40
     */
41 100
    protected function config()
42
    {
43 100
        return $this->make('config');
44
    }
45
46
    /**
47
     * Get the session store instance.
48
     *
49
     * @return \Illuminate\Session\Store
50
     */
51 18
    protected function session()
52
    {
53 18
        return $this->make('session.store');
54
    }
55
56
    /**
57
     * Get the tracker config.
58
     *
59
     * @param  string      $key
60
     * @param  mixed|null  $default
61
     *
62
     * @return mixed
63
     */
64 100
    protected function getConfig($key, $default = null)
65
    {
66 100
        return $this->config()->get("laravel-tracker.$key", $default);
67
    }
68
69
    /**
70
     * Make the model.
71
     *
72
     * @param  string  $name
73
     *
74
     * @return mixed
75
     */
76 82
    protected function makeModel($name)
77
    {
78 82
        return $this->make(
79 82
            $this->getConfig("models.$name")
80 41
        );
81
    }
82
83
    /**
84
     * Make/Get the instance from the app.
85
     *
86
     * @param  string  $abstract
87
     *
88
     * @return mixed
89
     */
90 106
    protected function make($abstract)
91
    {
92 106
        return $this->app->make($abstract);
93
    }
94
}
95