PrefetchAnalyticsData   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Analytics;
6
use Spatie\Analytics\Period;
7
use Illuminate\Console\Command;
8
9
class PrefetchAnalyticsData extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'analytics:prefetch';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Prefetch the analytics data.';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function handle()
31
    {
32
        $this->info('Prefetching analytics data...');
33
34
        if (empty(config('laravel-analytics.view_id'))) {
35
            $this->warn('No view id configured!');
36
37
            return;
38
        }
39
40
        Analytics::fetchTotalVisitorsAndPageViews(Period::days(14));
41
        Analytics::fetchTotalVisitorsAndPageViews(Period::days(365));
42
        Analytics::fetchMostVisitedPages(Period::days(365));
43
        Analytics::fetchTopReferrers(Period::days(365));
44
        Analytics::fetchTopBrowsers(Period::days(365));
45
46
        $this->info('Analytics data prefetched!');
47
    }
48
}
49