Conditions | 2 |
Paths | 2 |
Total Lines | 65 |
Code Lines | 37 |
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 |
||
31 | public function index() |
||
32 | { |
||
33 | $minutes = config('analytics.cache_lifetime_in_minutes'); |
||
34 | |||
35 | if (config('analytics.enabled')) { |
||
36 | // @codeCoverageIgnoreStart |
||
37 | $visitorsData = Cache::remember('Analytics.visitors', $minutes, function () { |
||
38 | return $this->buildVisitorsGraph(); |
||
39 | }); |
||
40 | |||
41 | $browsersData = Cache::remember('Analytics.browsers', $minutes, function () { |
||
42 | return $this->buildBrowsersGraph(); |
||
43 | }); |
||
44 | |||
45 | $countriesData = Cache::remember('Analytics.countries', $minutes, function () { |
||
46 | return $this->buildCountriesGraph(); |
||
47 | }); |
||
48 | |||
49 | $devicesGraph = Cache::remember('Analytics.devices', $minutes, function () { |
||
50 | return $this->buildDevicesGraph(); |
||
51 | }); |
||
52 | |||
53 | $topCountries = array_slice($countriesData->rows, 0, 3); |
||
54 | |||
55 | $operatingSystemGraph = Cache::remember('Analytics.operatingsystem', $minutes, function () { |
||
56 | return $this->buildOperatingSytemGraph(); |
||
57 | }); |
||
58 | |||
59 | $todayVisitors = Cache::remember('Analytics.todayvisitors', $minutes, function () { |
||
60 | return $this->buildTodayVisitors(); |
||
61 | }); |
||
62 | // @codeCoverageIgnoreEnd |
||
63 | } |
||
64 | |||
65 | $usersCount = Cache::remember('Analytics.users.count', $minutes, function () { |
||
66 | return User::count(); |
||
67 | }); |
||
68 | |||
69 | $articlesCount = Cache::remember('Analytics.articles.count', $minutes, function () { |
||
70 | return Article::count(); |
||
71 | }); |
||
72 | |||
73 | $commentsCount = Cache::remember('Analytics.comments.count', $minutes, function () { |
||
74 | return Comment::count(); |
||
75 | }); |
||
76 | |||
77 | $breadcrumbs = $this->breadcrumbs; |
||
78 | |||
79 | return view( |
||
80 | 'Admin::page.index', |
||
81 | compact( |
||
82 | 'breadcrumbs', |
||
83 | 'visitorsData', |
||
84 | 'browsersData', |
||
85 | 'countriesData', |
||
86 | 'topCountries', |
||
87 | 'devicesGraph', |
||
88 | 'operatingSystemGraph', |
||
89 | 'usersCount', |
||
90 | 'articlesCount', |
||
91 | 'commentsCount', |
||
92 | 'todayVisitors' |
||
93 | ) |
||
94 | ); |
||
95 | } |
||
96 | } |
||
97 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.