Passed
Push — master ( c6150b...ef80b0 )
by Mihail
05:01
created

ActionCache::cache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Network\Request;
9
use Ffcms\Core\Network\Response;
10
11
/**
12
 * Trait ActionCache
13
 * @package Apps\Controller\Admin\Main
14
 * @property View $view
15
 * @property Request $request
16
 * @property Response $response
17
 */
18
trait ActionCache
19
{
20
    /**
21
     * Clear cache data if submited
22
     * @return string|null
23
     */
24
    public function cache(): ?string
25
    {
26
        // check if submited
27
        if ($this->request->request->get('clearcache', false)) {
28
            // clear cache
29
            App::$Cache->clear();
30
            // add notification & redirect
31
            App::$Session->getFlashBag()->add('success', __('Cache cleared successfully'));
32
            $this->response->redirect('/');
33
        }
34
35
        // render output view
36
        return $this->view->render('main/clear_cache');
37
    }
38
}