Completed
Push — master ( 9d13eb...060bbf )
by Antonio Carlos
06:41
created

ServiceInstances   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
dl 0
loc 72
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A cache() 0 3 1
A messages() 0 3 1
A ipList() 0 3 1
A dataRepository() 0 3 1
A geoIp() 0 3 1
A getInstance() 0 9 2
A config() 0 3 1
A countries() 0 3 1
A getFromInstanceCache() 0 7 2
A ipAddress() 0 3 1
A setInstance() 0 3 1
A fileSystem() 0 3 1
1
<?php
2
3
namespace PragmaRX\Firewall\Support;
4
5
trait ServiceInstances
6
{
7
    public $instances = [];
8
9
    public function getInstance($binding)
10
    {
11
        if (is_null($instance = $this->getFromInstanceCache($binding))) {
12
            $instance = app('firewall.'.$binding);
13
        }
14
15
        $this->setInstance($binding, $instance);
16
17
        return $instance;
18
    }
19
20
    public function getFromInstanceCache($binding)
21
    {
22
        if (isset($this->instances[$binding])) {
23
            return $this->instances[$binding];
24
        }
25
26
        return null;
27
    }
28
29
    public function setInstance($binding, $instance)
30
    {
31
        $this->instances[$binding] = $instance;
32
    }
33
34
    public function countries()
35
    {
36
        return $this->getInstance('countries');
37
    }
38
39
    public function ipList()
40
    {
41
        return $this->getInstance('iplist');
42
    }
43
44
    public function messages()
45
    {
46
        return $this->getInstance('messages');
47
    }
48
49
    public function cache()
50
    {
51
        return $this->getInstance('cache');
52
    }
53
54
    public function config()
55
    {
56
        return $this->getInstance('config');
57
    }
58
59
    public function fileSystem()
60
    {
61
        return $this->getInstance('filesystem');
62
    }
63
64
    public function geoIp()
65
    {
66
        return $this->getInstance('geoip');
67
    }
68
69
    public function ipAddress()
70
    {
71
        return $this->getInstance('ipaddress');
72
    }
73
74
    public function dataRepository()
75
    {
76
        return $this->getInstance('datarepository');
77
    }
78
}
79