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