Passed
Pull Request — master (#610)
by John
22:48
created

DashboardController::environment()   B

Complexity

Conditions 9
Paths 128

Size

Total Lines 65
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 38
nc 128
nop 0
dl 0
loc 65
rs 7.5697
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
56
            ['name' => __('admin.home.envs.tlsv13'), 'value' => ["Not Supported", "Supported"][in_array("tlsv1.3", stream_get_transports())]],
57
        ];
58
59
        foreach ($envs as &$env) {
60
            $env['icon']="check-circle";
61
            $env['color']="wemd-teal-text";
62
        }
63
64
        // PHP Version Check
65
        $installedVersion=new Version(PHP_VERSION);
66
        $requireVersion=new Version("7.4.0");
67
        if (!($installedVersion->isGreaterThan($requireVersion) || $installedVersion->getVersionString()===$requireVersion->getVersionString())) {
68
            $envs[0]['icon']="close-circle";
69
            $envs[0]['color']="wemd-pink-text";
70
        }
71
72
        // Cache Driver Check
73
        if (config('cache.default')!="redis") {
74
            $envs[5]['icon']="close-circle";
75
            $envs[5]['color']="wemd-pink-text";
76
        }
77
78
        // Session Driver Check
79
        if (config('session.driver')!="redis") {
80
            $envs[6]['icon']="close-circle";
81
            $envs[6]['color']="wemd-pink-text";
82
        }
83
84
        // Queue Driver Check
85
        if (config('queue.default')!="database") {
86
            $envs[7]['icon']="close-circle";
87
            $envs[7]['color']="wemd-pink-text";
88
        }
89
90
        // Locale Check
91
        if (!in_array(strtolower(config('app.locale')), ['en', 'zh-cn'])) {
92
            $envs[9]['icon']="close-circle";
93
            $envs[9]['color']="wemd-pink-text";
94
        }
95
96
        // TLSv1.3 Check
97
        if ($envs[12]['value']=="Not Supported") {
98
            $envs[12]['icon']="close-circle";
99
            $envs[12]['color']="wemd-pink-text";
100
        }
101
102
        return view('admin::dashboard.environment', compact('envs'));
103
    }
104
}
105