Completed
Push — master ( 853dbc...35e61c )
by Iurii
01:26
created

Cache   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
C cmdClearCache() 0 28 7
1
<?php
2
3
/**
4
 * @package CLI
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2018, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\cli\controllers;
11
12
use gplcart\core\Cache as CoreCache;
13
14
/**
15
 * Handles commands related to system cache
16
 */
17
class Cache extends Base
18
{
19
20
    /**
21
     * Cache class instance
22
     * @var \gplcart\core\Cache $cache
23
     */
24
    protected $cache;
25
26
    /**
27
     * @param CoreCache $cache
28
     */
29
    public function __construct(CoreCache $cache)
30
    {
31
        parent::__construct();
32
33
        $this->cache = $cache;
34
    }
35
36
    /**
37
     * Callback for "cache-clear" command
38
     */
39
    public function cmdClearCache()
40
    {
41
        $id = $this->getParam(0);
42
        $all = $this->getParam('all');
43
44
        if (!isset($id) && empty($all)) {
45
            $this->errorExit($this->text('Invalid command'));
46
        }
47
48
        $result = false;
49
50
        if (isset($id)) {
51
            $pattern = $this->getParam('pattern');
52
            if (isset($pattern)) {
53
                $result = $this->cache->clear($id, array('pattern' => $pattern));
54
            } else {
55
                $result = $this->cache->clear($id);
56
            }
57
        } else if ($all) {
58
            $result = $this->cache->clear(null);
59
        }
60
61
        if (!$result) {
62
            $this->errorExit($this->text('An error occurred'));
63
        }
64
65
        $this->output();
66
    }
67
68
}
69