CachesController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionInvalidate() 0 14 2
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