AbstractDriver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 84
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
init() 0 1 ?
A update() 0 6 1
A getOption() 0 4 1
A hydrate() 0 4 1
1
<?php namespace Arcanedev\GeoIP\Drivers;
2
3
use Arcanedev\GeoIP\Contracts\GeoIPDriver;
4
use Arcanedev\GeoIP\Location;
5
use Illuminate\Support\Arr;
6
7
/**
8
 * Class     AbstractDriver
9
 *
10
 * @package  Arcanedev\GeoIP\Drivers
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
abstract class AbstractDriver implements GeoIPDriver
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * Driver options.
22
     *
23
     * @var array
24
     */
25
    protected $options = [];
26
27
    /* -----------------------------------------------------------------
28
     |  Constructor
29
     | -----------------------------------------------------------------
30
     */
31
32
    /**
33
     * AbstractDriver constructor.
34
     *
35
     * @param  array  $options
36
     */
37 45
    public function __construct(array $options = [])
38
    {
39 45
        $this->options = $options;
40 45
        $this->init();
41 45
    }
42
43
    /* -----------------------------------------------------------------
44
     |  Main Methods
45
     | -----------------------------------------------------------------
46
     */
47
48
    /**
49
     * Init the driver.
50
     */
51
    abstract protected function init();
52
53
    /**
54
     * Update the driver.
55
     *
56
     * @return bool
57
     *
58
     * @throws \Exception
59
     */
60
    public function update()
61
    {
62
        // Do nothing
63
64
        return true;
65
    }
66
67
    /* -----------------------------------------------------------------
68
     |  Other Methods
69
     | -----------------------------------------------------------------
70
     */
71
72
    /**
73
     * Get option value.
74
     *
75
     * @param  string  $key
76
     * @param  mixed   $default
77
     *
78
     * @return mixed
79
     */
80 18
    protected function getOption($key, $default = null)
81
    {
82 18
        return Arr::get($this->options, $key, $default);
83
    }
84
85
    /**
86
     * Hydrate the location entity.
87
     *
88
     * @param  array  $attributes
89
     *
90
     * @return \Arcanedev\GeoIP\Location
91
     */
92 12
    protected function hydrate(array $attributes = [])
93
    {
94 12
        return new Location($attributes);
95
    }
96
}
97