Completed
Push — master ( 1b4550...82aca0 )
by Iurii
04:48
created

Asset::cmdCacheClearAsset()   D

Complexity

Conditions 9
Paths 9

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 4.909
c 0
b 0
f 0
cc 9
eloc 16
nc 9
nop 0
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\commands;
11
12
use DirectoryIterator;
13
use gplcart\modules\cli\controllers\Command;
14
15
/**
16
 * Handles commands related to asset files (JS and CSS)
17
 */
18
class Asset extends Command
19
{
20
21
    /**
22
     * Constructor
23
     */
24
    public function __construct()
25
    {
26
        parent::__construct();
27
    }
28
29
    /**
30
     * Callback for "asset-cache-clear" command
31
     */
32
    public function cmdCacheClearAsset()
33
    {
34
        $params = $this->getParam();
35
36
        if (empty($params)) {
37
            foreach (new DirectoryIterator(GC_DIR_ASSET_COMPILED) as $file) {
38
                if ($file->isDir() && !$file->isDot()) {
39
                    gplcart_file_delete_recursive($file->getRealPath());
40
                }
41
            }
42
        } else {
43
44
            $file = null;
45
46
            if (!empty($params['css'])) {
47
                $file = GC_DIR_ASSET_COMPILED . '/css';
48
            } else if (!empty($params['js'])) {
49
                $file = GC_DIR_ASSET_COMPILED . '/js';
50
            }
51
52
            if (empty($file) || !is_dir($file)) {
53
                $this->errorAndExit($this->text('Invalid command'));
54
            }
55
56
            gplcart_file_delete_recursive($file);
57
        }
58
59
        $this->output();
60
    }
61
62
}
63