DashboardController::general()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 18
c 0
b 0
f 0
rs 9.8333
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Admin\Controllers;
4
5
use App\Models\Update\UpdateModel;
6
use Illuminate\Support\Arr;
7
use PharIo\Version\Version;
8
9
class DashboardController
10
{
11
    /**
12
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
13
     */
14
    public static function general()
15
    {
16
        $version=UpdateModel::checkUpdate();
17
18
        $status=[
19
            ['name' => __("admin.home.version"), 'value' => version()],
20
            ['name' => __("admin.home.latest"), 'value' => is_null($version) ? 'Failed to fetch latest version' : $version["name"]],
21
            ['name' => __("admin.home.problems"), 'value' => \App\Models\Eloquent\Problem::count()],
22
            ['name' => __("admin.home.solutions"), 'value' => \App\Models\Eloquent\ProblemSolution::count()],
23
            ['name' => __("admin.home.submissions"), 'value' => \App\Models\Eloquent\Submission::count()],
24
            ['name' => __("admin.home.contests"), 'value' => \App\Models\Eloquent\Contest::count()],
25
            ['name' => __("admin.home.users"), 'value' => \App\Models\Eloquent\User::count()],
26
            ['name' => __("admin.home.groups"), 'value' => \App\Models\Eloquent\Group::count()],
27
        ];
28
29
        return view('admin::dashboard.general', [
30
            'status'=>$status,
31
            'version'=>$version
32
        ]);
33
    }
34
35
    /**
36
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
37
     */
38
    public static function environment()
39
    {
40
        $envs=[
41
            ['name' => __('admin.home.envs.php'), 'value' => 'PHP/'.PHP_VERSION],
42
            ['name' => __('admin.home.envs.laravel'), 'value' => app()->version()],
0 ignored issues
show
introduced by
The method version() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
            ['name' => __('admin.home.envs.laravel'), 'value' => app()->/** @scrutinizer ignore-call */ version()],
Loading history...
43
            ['name' => __('admin.home.envs.cgi'), 'value' => php_sapi_name()],
44
            ['name' => __('admin.home.envs.uname'), 'value' => php_uname()],
45
            ['name' => __('admin.home.envs.server'), 'value' => Arr::get($_SERVER, 'SERVER_SOFTWARE')],
46
47
            ['name' => __('admin.home.envs.cache'), 'value' => config('cache.default')],
48
            ['name' => __('admin.home.envs.session'), 'value' => config('session.driver')],
49
            ['name' => __('admin.home.envs.queue'), 'value' => config('queue.default')],
50
51
            ['name' => __('admin.home.envs.timezone'), 'value' => config('app.timezone')],
52
            ['name' => __('admin.home.envs.locale'), 'value' => config('app.locale')],
53
            ['name' => __('admin.home.envs.env'), 'value' => config('app.env')],
54
            ['name' => __('admin.home.envs.url'), 'value' => config('app.url')],
55
            ['name' => __('admin.home.envs.babelMirror'), 'value' => config('babel.mirror')],
56
57
            ['name' => __('admin.home.envs.tlsv13'), 'value' => ["Not Supported", "Supported"][in_array("tlsv1.3", stream_get_transports())]],
58
        ];
59
60
        foreach ($envs as &$env) {
61
            $env['icon']="check-circle";
62
            $env['color']="wemd-teal-text";
63
        }
64
65
        // PHP Version Check
66
        $installedVersion=new Version(PHP_VERSION);
67
        $requireVersion=new Version("7.4.0");
68
        if (!($installedVersion->isGreaterThan($requireVersion) || $installedVersion->getVersionString()===$requireVersion->getVersionString())) {
69
            $envs[0]['icon']="close-circle";
70
            $envs[0]['color']="wemd-pink-text";
71
        }
72
73
        // Cache Driver Check
74
        if (config('cache.default')!="redis") {
75
            $envs[5]['icon']="close-circle";
76
            $envs[5]['color']="wemd-pink-text";
77
        }
78
79
        // Session Driver Check
80
        if (config('session.driver')!="redis") {
81
            $envs[6]['icon']="close-circle";
82
            $envs[6]['color']="wemd-pink-text";
83
        }
84
85
        // Queue Driver Check
86
        if (config('queue.default')!="database") {
87
            $envs[7]['icon']="close-circle";
88
            $envs[7]['color']="wemd-pink-text";
89
        }
90
91
        // Locale Check
92
        if (!in_array(strtolower(config('app.locale')), ['en', 'zh-cn'])) {
93
            $envs[9]['icon']="close-circle";
94
            $envs[9]['color']="wemd-pink-text";
95
        }
96
97
        // TLSv1.3 Check
98
        if ($envs[12]['value']=="Not Supported") {
99
            $envs[12]['icon']="close-circle";
100
            $envs[12]['color']="wemd-pink-text";
101
        }
102
103
        return view('admin::dashboard.environment', compact('envs'));
104
    }
105
}
106