Conditions | 2 |
Paths | 2 |
Total Lines | 55 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
26 | public function index() |
||
27 | { |
||
28 | $minutes = config('analytics.cache_lifetime_in_minutes'); |
||
29 | |||
30 | $viewDatas = []; |
||
31 | |||
32 | if (!App::environment('testing')) { |
||
33 | |||
34 | /*$visitorsData = Cache::remember('Analytics.visitors', $minutes, function () { |
||
35 | return $this->buildVisitorsGraph(); |
||
36 | }); |
||
37 | $viewDatas[] = 'visitorsData'; |
||
38 | |||
39 | $browsersData = Cache::remember('Analytics.browsers', $minutes, function () { |
||
40 | return $this->buildBrowsersGraph(); |
||
41 | }); |
||
42 | $viewDatas[] = 'browsersData'; |
||
43 | |||
44 | $devicesGraph = Cache::remember('Analytics.devices', $minutes, function () { |
||
45 | return $this->buildDevicesGraph(); |
||
46 | }); |
||
47 | $viewDatas[] = 'devicesGraph'; |
||
48 | |||
49 | $operatingSystemGraph = Cache::remember('Analytics.operatingsystem', $minutes, function () { |
||
50 | return $this->buildOperatingSystemGraph(); |
||
51 | }); |
||
52 | $viewDatas[] = 'operatingSystemGraph';*/ |
||
53 | |||
54 | $todayVisitors = Cache::remember('Analytics.todayvisitors', $minutes, function () { |
||
55 | return $this->buildTodayVisitors(); |
||
56 | }); |
||
57 | $viewDatas[] = 'todayVisitors'; |
||
58 | } |
||
59 | |||
60 | $usersCount = Cache::remember('Analytics.users.count', $minutes, function () { |
||
61 | return User::count(); |
||
62 | }); |
||
63 | $viewDatas[] = 'usersCount'; |
||
64 | |||
65 | $articlesCount = Cache::remember('Analytics.articles.count', $minutes, function () { |
||
66 | return BlogArticle::count(); |
||
67 | }); |
||
68 | $viewDatas[] = 'articlesCount'; |
||
69 | |||
70 | $commentsCount = Cache::remember('Analytics.comments.count', $minutes, function () { |
||
71 | return BlogComment::count(); |
||
72 | }); |
||
73 | $viewDatas[] = 'commentsCount'; |
||
74 | |||
75 | $breadcrumbs = $this->breadcrumbs; |
||
76 | $viewDatas[] = 'breadcrumbs'; |
||
77 | |||
78 | return view( |
||
79 | 'Admin.page.index', |
||
80 | compact($viewDatas) |
||
81 | ); |
||
84 |