Passed
Push — master ( f96468...e8dc9f )
by M. Mikkel
03:43
created

CachesController::actionInvalidate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
namespace mmikkel\cacheflag\console\controllers;
4
5
use craft\console\Controller;
6
7
use yii\console\ExitCode;
8
9
use mmikkel\cacheflag\CacheFlag;
10
11
/**
12
 * Class CachesController
13
 * @package mmikkel\cacheflag\console\controllers
14
 * @since 1.2.0
15
 */
16
class CachesController extends Controller
17
{
18
19
    /**
20
     * Invalidate all flagged caches, or caches flagged with one or several particular flags
21
     *
22
     * @param string $flags
23
     * @return int
24
     */
25
    public function actionInvalidate(string $flags = '')
26
    {
27
28
        $flags = \preg_replace('/\s+/', '', $flags);
29
        $flags = \array_unique(\array_filter(\explode(',', $flags)));
30
31
        if (empty($flags)) {
32
            CacheFlag::getInstance()->cacheFlag->invalidateAllFlaggedCaches();
33
            return ExitCode::OK;
34
        }
35
36
        CacheFlag::getInstance()->cacheFlag->invalidateFlaggedCachesByFlags($flags);
37
38
        return ExitCode::OK;
39
40
    }
41
42
}
43