ClearCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 109
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 12 2
A config() 0 4 1
A getDefaultCache() 0 4 1
A isSupported() 0 5 2
1
<?php namespace Arcanedev\GeoIP\Console;
2
3
use Arcanedev\GeoIP\Contracts\GeoIPCache;
4
use Arcanedev\Support\Bases\Command;
5
6
/**
7
 * Class     ClearCommand
8
 *
9
 * @package  Arcanedev\GeoIP\Console
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class ClearCommand extends Command
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * The console command name.
21
     *
22
     * @var string
23
     */
24
    protected $name = 'geoip:clear';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Clear the GeoIP cached data.';
32
33
    /**
34
     * Supported cache stores.
35
     *
36
     * @var array
37
     */
38
    protected $supported = ['apc', 'array', 'memcached', 'redis'];
39
40
    /**
41
     * The GeoIP Cache instance.
42
     *
43
     * @var \Arcanedev\GeoIP\Contracts\GeoIPCache
44
     */
45
    private $cache;
46
47
    /* -----------------------------------------------------------------
48
     |  Constructor
49
     | -----------------------------------------------------------------
50
     */
51
52
    /**
53
     * ClearCommand constructor.
54
     *
55
     * @param  \Arcanedev\GeoIP\Contracts\GeoIPCache  $cache
56
     */
57
    public function __construct(GeoIPCache $cache)
58
    {
59
        parent::__construct();
60
61
        $this->cache = $cache;
62
    }
63
64
    /* -----------------------------------------------------------------
65
     |  Main Methods
66
     | -----------------------------------------------------------------
67
     */
68
69
    /**
70
     * Execute the console command.
71
     */
72
    public function handle()
73
    {
74
        if ($this->isSupported($default = $this->getDefaultCache())) {
75
            $this->comment('Clearing the cache data...');
76
77
            $this->cache->flush();
78
79
            $this->info("Cache clearing was completed!");
80
        }
81
        else
82
            $this->error("Default cache system [$default] does not support tags");
83
    }
84
85
    /* -----------------------------------------------------------------
86
     |  Other Methods
87
     | -----------------------------------------------------------------
88
     */
89
90
    /**
91
     * Get the config repository.
92
     *
93
     * @return \Illuminate\Contracts\Config\Repository
94
     */
95
    protected function config()
96
    {
97
        return $this->laravel['config'];
98
    }
99
100
    /**
101
     * Get the default cache.
102
     *
103
     * @return string
104
     */
105
    protected function getDefaultCache()
106
    {
107
        return $this->config()->get('cache.default');
108
    }
109
110
    /**
111
     * Is cache flushing supported.
112
     *
113
     * @return bool
114
     */
115
    protected function isSupported($default)
116
    {
117
        return in_array($default, $this->supported) &&
118
               ! empty($this->config()->get('geoip.cache.tags', []));
119
    }
120
}
121