Code Duplication    Length = 26-26 lines in 2 locations

app/Http/Controllers/DashboardController.php 2 locations

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