Conditions | 1 |
Paths | 1 |
Total Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
143 | public function getGAValues() { |
||
144 | |||
145 | /** |
||
146 | * Visitors and pageviews this week |
||
147 | */ |
||
148 | $visitorsThisWeek = $this->gaGetVisitorsPageviews(7, 'visitors'); |
||
149 | $pageviewsThisWeek = $this->gaGetVisitorsPageviews(7, 'pageViews'); |
||
150 | |||
151 | /** |
||
152 | * Visitors and pageviews two weeks |
||
153 | */ |
||
154 | $visitorsTwoWeeks = $this->gaGetVisitorsPageviews(14, 'visitors'); |
||
155 | $pageviewsTwoWeeks = $this->gaGetVisitorsPageviews(14, 'pageViews'); |
||
156 | |||
157 | /** |
||
158 | * Visitors and pageviews last week |
||
159 | */ |
||
160 | $visitorsLastWeek = $visitorsTwoWeeks - $visitorsThisWeek; |
||
161 | $pageviewsLastWeek = $pageviewsTwoWeeks - $pageviewsThisWeek; |
||
162 | $visitorsPercentThisWeek = $this->getPercentDifference($visitorsLastWeek, $visitorsThisWeek); |
||
163 | $pageviewsPercentThisWeek = $this->getPercentDifference($pageviewsLastWeek, $pageviewsThisWeek); |
||
164 | |||
165 | /** |
||
166 | * Visitors and pageviews this month |
||
167 | */ |
||
168 | $visitorsThisMonth = $this->gaGetVisitorsPageviews(30, 'visitors'); |
||
169 | $pageviewsThisMonth = $this->gaGetVisitorsPageviews(30, 'pageViews'); |
||
170 | |||
171 | /** |
||
172 | * Visitors and pageviews last month |
||
173 | */ |
||
174 | $visitorsTwoMonths = $this->gaGetVisitorsPageviews(60, 'visitors'); |
||
175 | $pageviewsTwoMonths = $this->gaGetVisitorsPageviews(60, 'pageViews'); |
||
176 | |||
177 | /** |
||
178 | * Visitors and pageviews last month |
||
179 | */ |
||
180 | $visitorsLastMonth = $visitorsTwoMonths - $visitorsThisMonth; |
||
181 | $pageviewsLastMonth = $pageviewsTwoMonths - $pageviewsThisMonth; |
||
182 | $visitorsPercentThisMonth = $this->getPercentDifference($visitorsLastMonth, $visitorsThisMonth); |
||
183 | $pageviewsPercentThisMonth = $this->getPercentDifference($pageviewsLastMonth, $pageviewsThisMonth); |
||
184 | |||
185 | /** |
||
186 | * Refefers |
||
187 | * |
||
188 | */ |
||
189 | $topReferers = \Analytics::getTopReferrers(30, 10); |
||
190 | |||
191 | /** |
||
192 | * Visitors and pageviews for 30 days |
||
193 | */ |
||
194 | $visitorsPageviewsChart = \Analytics::getVisitorsAndPageViews(30); |
||
195 | |||
196 | $ga = [ |
||
197 | 'visitors_this_week' => $visitorsThisWeek, |
||
198 | 'visitors_last_week' => $visitorsLastWeek, |
||
199 | 'visitors_percent_this_week' => $visitorsPercentThisWeek, |
||
200 | 'pageviews_this_week' => $pageviewsThisWeek, |
||
201 | 'pageviews_last_week' => $pageviewsLastWeek, |
||
202 | 'pageviews_percent_this_week' => $pageviewsPercentThisWeek, |
||
203 | 'visitors_this_month' => $visitorsThisMonth, |
||
204 | 'visitors_last_month' => $visitorsLastMonth, |
||
205 | 'visitors_percent_this_month' => $visitorsPercentThisMonth, |
||
206 | 'pageviews_this_month' => $pageviewsThisMonth, |
||
207 | 'pageviews_last_month' => $pageviewsLastMonth, |
||
208 | 'pageviews_percent_this_month' => $pageviewsPercentThisMonth, |
||
209 | 'top_referers' => $topReferers, |
||
210 | 'visitors_pageviews_chart' => $visitorsPageviewsChart |
||
211 | ]; |
||
212 | |||
213 | return $ga; |
||
214 | } |
||
215 | } |
||
216 |