PrefetchAnalyticsData::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
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