Passed
Push — master ( 81f334...c86e8c )
by Mihail
03:35
created

ActionSessions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A sessions() 0 19 2
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
use Apps\ActiveRecord\Session;
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 ActionSessions
13
 * @package Apps\Controller\Admin\Main
14
 * @property Request $request
15
 * @property Response $response
16
 * @property View $view
17
 */
18
trait ActionSessions
19
{
20
    /**
21
     * Clear all sessions data
22
     * @return string
23
     * @throws \Ffcms\Core\Exception\SyntaxException
24
     */
25
    public function sessions()
26
    {
27
        // get all sessions data
28
        $sessions = Session::all();
29
30
        // check if action is submited
31
        if ($this->request->request->get('clearsessions', false)) {
32
            // truncate table
33
            App::$Database->table('sessions')->truncate();
34
            // add notification and make redirect to main
35
            App::$Session->getFlashBag()->add('success', __('Sessions cleared successfully'));
36
            $this->response->redirect('/');
37
        }
38
39
        // render output view
40
        return $this->view->render('clear_sessions', [
41
            'count' => $sessions->count()
42
        ]);
43
    }
44
}
45