Passed
Push — 5.0.0 ( 49e1c0...87aae2 )
by Fèvre
06:22
created

PageController::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 55
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 20
nc 2
nop 0
dl 0
loc 55
rs 9.6
c 2
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
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers\Admin;
6
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Foundation\Application;
10
use Illuminate\Support\Facades\App;
11
use Illuminate\Support\Facades\Cache;
12
use Xetaravel\Http\Components\AnalyticsComponent;
13
use Xetaravel\Models\BlogArticle;
14
use Xetaravel\Models\BlogComment;
15
use Xetaravel\Models\User;
16
17
class PageController extends Controller
18
{
19
    use AnalyticsComponent;
0 ignored issues
show
introduced by
The trait Xetaravel\Http\Components\AnalyticsComponent requires some properties which are not provided by Xetaravel\Http\Controllers\Admin\PageController: $totalsForAllResults, $endDate
Loading history...
20
21
    /**
22
     * Show the application dashboard.
23
     *
24
     * @return Factory|View|Application|\Illuminate\View\View|object
25
     */
26
    public function index()
27
    {
28
        $minutes = config('analytics.cache_lifetime_in_minutes');
29
30
        $viewDatas = [];
31
32
        if (!App::environment('testing')) {
33
34
            /*$visitorsData = Cache::remember('Analytics.visitors', $minutes, function () {
35
                return $this->buildVisitorsGraph();
36
            });
37
            $viewDatas[] = 'visitorsData';
38
39
            $browsersData = Cache::remember('Analytics.browsers', $minutes, function () {
40
                return $this->buildBrowsersGraph();
41
            });
42
            $viewDatas[] = 'browsersData';
43
44
            $devicesGraph = Cache::remember('Analytics.devices', $minutes, function () {
45
                return $this->buildDevicesGraph();
46
            });
47
            $viewDatas[] = 'devicesGraph';
48
49
            $operatingSystemGraph = Cache::remember('Analytics.operatingsystem', $minutes, function () {
50
                return $this->buildOperatingSystemGraph();
51
            });
52
            $viewDatas[] = 'operatingSystemGraph';*/
53
54
            $todayVisitors = Cache::remember('Analytics.todayvisitors', $minutes, function () {
55
                return $this->buildTodayVisitors();
56
            });
57
            $viewDatas[] = 'todayVisitors';
58
        }
59
60
        $usersCount = Cache::remember('Analytics.users.count', $minutes, function () {
61
            return User::count();
62
        });
63
        $viewDatas[] = 'usersCount';
64
65
        $articlesCount = Cache::remember('Analytics.articles.count', $minutes, function () {
66
            return BlogArticle::count();
67
        });
68
        $viewDatas[] = 'articlesCount';
69
70
        $commentsCount = Cache::remember('Analytics.comments.count', $minutes, function () {
71
            return BlogComment::count();
72
        });
73
        $viewDatas[] = 'commentsCount';
74
75
        $breadcrumbs = $this->breadcrumbs;
76
        $viewDatas[] = 'breadcrumbs';
77
78
        return view(
79
            'Admin.page.index',
80
            compact($viewDatas)
81
        );
82
    }
83
}
84