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

ActionIndex   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B index() 0 35 3
1
<?php
2
3
namespace Apps\Controller\Admin\Main;
4
5
use Apps\Model\Install\Main\EntityCheck;
6
use Extend\Version;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Helper\Environment;
10
use Ffcms\Core\Helper\FileSystem\Directory;
11
use Ffcms\Core\Network\Request;
12
use Ffcms\Core\Network\Response;
13
14
/**
15
 * Trait ActionIndex
16
 * @package Apps\Controller\Admin\Main
17
 * @property Request $request
18
 * @property Response $response
19
 * @property View $view
20
 */
21
trait ActionIndex
22
{
23
    /**
24
     * Index page of admin dashboard
25
     * @return string
26
     * @throws \Ffcms\Core\Exception\SyntaxException
27
     */
28
    public function index(): ?string
29
    {
30
        // get cached statistics
31
        $rootSize = App::$Cache->getItem('root.size');
32
        $loadAvg = App::$Cache->getItem('load.avarage');
33
        if (!$rootSize->isHit()) {
34
            $calcSize = round(Directory::size('/') / (1024*1000), 2) . ' mb';
35
            $rootSize->set($calcSize);
36
            $rootSize->expiresAfter(86400);
37
            App::$Cache->save($rootSize);
38
        }
39
        if (!$loadAvg->isHit()) {
40
            $loadAvg->set(Environment::loadAverage());
41
            $loadAvg->expiresAfter(300);
42
            App::$Cache->save($loadAvg);
43
        }
44
45
        // prepare system statistic
46
        $stats = [
47
            'ff_version' => Version::VERSION . ' (' . Version::DATE . ')',
48
            'php_version' => Environment::phpVersion() . ' (' . Environment::phpSAPI() . ')',
49
            'os_name' => Environment::osName(),
50
            'database_name' => App::$Database->connection()->getDatabaseName() . ' (' . App::$Database->connection()->getDriverName() . ')',
51
            'file_size' => $rootSize->get(),
52
            'load_avg' => $loadAvg->get()
53
        ];
54
        // check directory chmods and other environment features
55
        $model = new EntityCheck();
56
57
        // render view output
58
        return $this->view->render('index', [
59
            'stats' => $stats,
60
            'check' => $model
61
        ]);
62
    }
63
}
64