Code Duplication    Length = 26-26 lines in 2 locations

app/Http/Controllers/DashboardController.php 2 locations

@@ 80-105 (lines=26) @@
77
     *
78
     * @return \Illuminate\Support\Collection
79
     */
80
    protected function getIssues()
81
    {
82
        $allIssues = Issue::whereBetween('created_at', [
83
            $this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00',
84
            $this->startDate->format('Y-m-d').' 23:59:59',
85
        ])->orderBy('created_at', 'desc')->get()->groupBy(function (Issue $issue) {
86
            return (new Date($issue->created_at))
87
                ->setTimezone($this->dateTimeZone)->toDateString();
88
        });
89
90
        // Add in days that have no issues
91
        foreach (range(0, 30) as $i) {
92
            $date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
93
94
            if (! isset($allIssues[$date->toDateString()])) {
95
                $allIssues[$date->toDateString()] = [];
96
            }
97
        }
98
99
        // Sort the array so it takes into account the added days
100
        $allIssues = $allIssues->sortBy(function ($value, $key) {
101
            return strtotime($key);
102
        }, SORT_REGULAR, false);
103
104
        return $allIssues;
105
    }
106
107
    /**
108
     * Fetches all of the subscribers over the last 30 days.
@@ 112-137 (lines=26) @@
109
     *
110
     * @return \Illuminate\Support\Collection
111
     */
112
    protected function getSubscribers()
113
    {
114
        $allSubscribers = Subscriber::whereBetween('created_at', [
115
            $this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00',
116
            $this->startDate->format('Y-m-d').' 23:59:59',
117
        ])->orderBy('created_at', 'desc')->get()->groupBy(function (Subscriber $issue) {
118
            return (new Date($issue->created_at))
119
                ->setTimezone($this->dateTimeZone)->toDateString();
120
        });
121
122
        // Add in days that have no issues
123
        foreach (range(0, 30) as $i) {
124
            $date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
125
126
            if (! isset($allSubscribers[$date->toDateString()])) {
127
                $allSubscribers[$date->toDateString()] = [];
128
            }
129
        }
130
131
        // Sort the array so it takes into account the added days
132
        $allSubscribers = $allSubscribers->sortBy(function ($value, $key) {
133
            return strtotime($key);
134
        }, SORT_REGULAR, false);
135
136
        return $allSubscribers;
137
    }
138
}
139