Completed
Push — administration ( 67d1c3...18dbd2 )
by Fèvre
05:11 queued 02:35
created

PageController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Http\Controllers\Admin;
3
4
use Carbon\Carbon;
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Cache;
7
use Xetaravel\Http\Components\AnalyticsComponent;
8
use Xetaravel\Models\Article;
9
use Xetaravel\Models\Comment;
10
use Xetaravel\Models\User;
11
12
class PageController extends Controller
13
{
14
    use AnalyticsComponent;
15
16
    /**
17
     * Constructor
18
     */
19
    public function __construct()
20
    {
21
        parent::__construct();
22
23
        $this->endDate = Carbon::now()->subDay();
24
    }
25
26
    /**
27
     * Show the application dashboard.
28
     *
29
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
30
     */
31
    public function index()
32
    {
33
        $minutes = config('analytics.cache_lifetime_in_minutes');
34
35
        if (config('analytics.enabled')) {
36
            // @codeCoverageIgnoreStart
37
            $visitorsData = Cache::remember('Analytics.visitors', $minutes, function () {
38
                return $this->buildVisitorsGraph();
39
            });
40
41
            $browsersData = Cache::remember('Analytics.browsers', $minutes, function () {
42
                return $this->buildBrowsersGraph();
43
            });
44
45
            $countriesData = Cache::remember('Analytics.countries', $minutes, function () {
46
                return $this->buildCountriesGraph();
47
            });
48
49
            $devicesGraph = Cache::remember('Analytics.devices', $minutes, function () {
50
                return $this->buildDevicesGraph();
51
            });
52
53
            $topCountries = array_slice($countriesData->rows, 0, 3);
54
55
            $operatingSystemGraph = Cache::remember('Analytics.operatingsystem', $minutes, function () {
56
                return $this->buildOperatingSytemGraph();
57
            });
58
59
            $todayVisitors = Cache::remember('Analytics.todayvisitors', $minutes, function () {
60
                return $this->buildTodayVisitors();
61
            });
62
            // @codeCoverageIgnoreEnd
63
        }
64
65
        $usersCount = Cache::remember('Analytics.users.count', $minutes, function () {
66
            return User::count();
67
        });
68
69
        $articlesCount = Cache::remember('Analytics.articles.count', $minutes, function () {
70
            return Article::count();
71
        });
72
73
        $commentsCount = Cache::remember('Analytics.comments.count', $minutes, function () {
74
            return Comment::count();
75
        });
76
77
        $breadcrumbs = $this->breadcrumbs;
0 ignored issues
show
Bug introduced by
The property breadcrumbs does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
78
79
        return view(
80
            'Admin::page.index',
81
            compact(
82
                'breadcrumbs',
83
                'visitorsData',
84
                'browsersData',
85
                'countriesData',
86
                'topCountries',
87
                'devicesGraph',
88
                'operatingSystemGraph',
89
                'usersCount',
90
                'articlesCount',
91
                'commentsCount',
92
                'todayVisitors'
93
            )
94
        );
95
    }
96
}
97