Completed
Push — master ( 35e61c...496f6c )
by Iurii
01:33
created

Asset   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B cmdCacheClearAsset() 0 20 6
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 DirectoryIterator;
13
14
/**
15
 * Handles commands related to asset files (JS and CSS)
16
 */
17
class Asset extends Base
18
{
19
20
    /**
21
     * Constructor
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
    }
27
28
    /**
29
     * Callback for "asset-cache-clear" command
30
     */
31
    public function cmdCacheClearAsset()
32
    {
33
        $type = $this->getParam(0);
34
35
        if (empty($type)) {
36
            foreach (new DirectoryIterator(GC_DIR_ASSET_COMPILED) as $file) {
37
                if ($file->isDir() && !$file->isDot()) {
38
                    gplcart_file_delete_recursive($file->getRealPath());
39
                }
40
            }
41
        } else {
42
            $file = GC_DIR_ASSET_COMPILED . "/$type";
43
            if (!is_dir($file)) {
44
                $this->errorAndExit($this->text('Invalid command'));
45
            }
46
            gplcart_file_delete_recursive($file);
47
        }
48
49
        $this->output();
50
    }
51
52
}
53