x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.

Code Duplication    Length = 16-21 lines in 4 locations

src/Analytics.php 4 locations

@@ 43-59 (lines=17) @@
40
        return $this;
41
    }
42
43
    public function fetchVisitorsAndPageViews(Period $period): Collection
44
    {
45
        $response = $this->performQuery(
46
            $period,
47
            'ga:users,ga:pageviews',
48
            ['dimensions' => 'ga:date,ga:pageTitle']
49
        );
50
51
        return collect($response['rows'] ?? [])->map(function (array $dateRow) {
52
            return [
53
                'date' => Carbon::createFromFormat('Ymd', $dateRow[0]),
54
                'pageTitle' => $dateRow[1],
55
                'visitors' => (int) $dateRow[2],
56
                'pageViews' => (int) $dateRow[3],
57
            ];
58
        });
59
    }
60
61
    public function fetchTotalVisitorsAndPageViews(Period $period): Collection
62
    {
@@ 61-76 (lines=16) @@
58
        });
59
    }
60
61
    public function fetchTotalVisitorsAndPageViews(Period $period): Collection
62
    {
63
        $response = $this->performQuery(
64
            $period,
65
            'ga:users,ga:pageviews',
66
            ['dimensions' => 'ga:date']
67
        );
68
69
        return collect($response['rows'] ?? [])->map(function (array $dateRow) {
70
            return [
71
                'date' => Carbon::createFromFormat('Ymd', $dateRow[0]),
72
                'visitors' => (int) $dateRow[1],
73
                'pageViews' => (int) $dateRow[2],
74
            ];
75
        });
76
    }
77
78
    public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection
79
    {
@@ 78-98 (lines=21) @@
75
        });
76
    }
77
78
    public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection
79
    {
80
        $response = $this->performQuery(
81
            $period,
82
            'ga:pageviews',
83
            [
84
                'dimensions' => 'ga:pagePath,ga:pageTitle',
85
                'sort' => '-ga:pageviews',
86
                'max-results' => $maxResults,
87
            ]
88
        );
89
90
        return collect($response['rows'] ?? [])
91
            ->map(function (array $pageRow) {
92
                return [
93
                    'url' => $pageRow[0],
94
                    'pageTitle' => $pageRow[1],
95
                    'pageViews' => (int) $pageRow[2],
96
                ];
97
            });
98
    }
99
100
    public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection
101
    {
@@ 100-117 (lines=18) @@
97
            });
98
    }
99
100
    public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection
101
    {
102
        $response = $this->performQuery($period,
103
            'ga:pageviews',
104
            [
105
                'dimensions' => 'ga:fullReferrer',
106
                'sort' => '-ga:pageviews',
107
                'max-results' => $maxResults,
108
            ]
109
        );
110
111
        return collect($response['rows'] ?? [])->map(function (array $pageRow) {
112
            return [
113
                'url' => $pageRow[0],
114
                'pageViews' => (int) $pageRow[1],
115
            ];
116
        });
117
    }
118
119
    public function fetchTopBrowsers(Period $period, int $maxResults = 10): Collection
120
    {