Completed
Push — master ( 54924a...1b4550 )
by Iurii
02:15
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;
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
        $params = $this->getParam();
34
35
        if (empty($params)) {
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
43
            $file = null;
44
45
            if (!empty($params['css'])) {
46
                $file = GC_DIR_ASSET_COMPILED . '/css';
47
            } else if (!empty($params['js'])) {
48
                $file = GC_DIR_ASSET_COMPILED . '/js';
49
            }
50
51
            if (empty($file) || !is_dir($file)) {
52
                $this->errorAndExit($this->text('Invalid command'));
53
            }
54
55
            gplcart_file_delete_recursive($file);
56
        }
57
58
        $this->output();
59
    }
60
61
}
62