Conditions | 6 |
Paths | 6 |
Total Lines | 58 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
70 | public function getBodyHtml() |
||
71 | { |
||
72 | $view = Craft::$app->getView(); |
||
73 | |||
74 | if (Analytics::$plugin->getAnalytics()->checkPluginRequirements()) { |
||
75 | if (Analytics::$plugin->getSettings()->enableWidgets) { |
||
76 | $reportingViews = Analytics::$plugin->getViews()->getViews(); |
||
77 | |||
78 | if (count($reportingViews) > 0) { |
||
79 | $widgetSettings = $this->settings; |
||
80 | |||
81 | $reportingView = Analytics::$plugin->getViews()->getViewById($widgetSettings['viewId']); |
||
82 | |||
83 | if ($reportingView) { |
||
84 | $plugin = Craft::$app->getPlugins()->getPlugin('analytics'); |
||
85 | $pluginSettings = $plugin->getSettings(); |
||
86 | |||
87 | if (!empty($pluginSettings['enableRealtime'])) { |
||
88 | $realtimeRefreshInterval = Analytics::$plugin->getAnalytics()->getRealtimeRefreshInterval(); |
||
89 | |||
90 | $widgetId = $this->id; |
||
91 | $widgetOptions = [ |
||
92 | 'viewId' => $widgetSettings['viewId'], |
||
93 | 'refreshInterval' => $realtimeRefreshInterval, |
||
94 | ]; |
||
95 | |||
96 | $view->registerTranslations('analytics', [ |
||
97 | 'Minutes ago', |
||
98 | 'Pageviews', |
||
99 | '{count} minute ago', |
||
100 | '{count} minutes ago', |
||
101 | ]); |
||
102 | |||
103 | $view->registerJsFile('//www.gstatic.com/charts/loader.js', [ |
||
104 | 'position' => View::POS_HEAD, |
||
105 | ]); |
||
106 | $view->registerAssetBundle(RealtimeReportWidgetAsset::class); |
||
107 | $view->registerJs('var AnalyticsChartLanguage = "'.Craft::$app->language.'";', true); |
||
108 | $view->registerJs('new Analytics.Realtime("widget'.$widgetId.'", '.Json::encode($widgetOptions).');'); |
||
109 | |||
110 | return $view->renderTemplate('analytics/_components/widgets/Realtime/body', [ |
||
111 | 'reportingView' => $reportingView |
||
112 | ]); |
||
113 | } |
||
114 | |||
115 | return $view->renderTemplate('analytics/_components/widgets/Realtime/disabled'); |
||
116 | } |
||
117 | |||
118 | return $view->renderTemplate('analytics/_special/view-not-configured'); |
||
119 | } |
||
120 | |||
121 | return $view->renderTemplate('analytics/_special/no-views'); |
||
122 | } |
||
123 | |||
124 | return $view->renderTemplate('analytics/_components/widgets/Realtime/disabled'); |
||
125 | } |
||
126 | |||
127 | return $view->renderTemplate('analytics/_special/not-connected'); |
||
128 | } |
||
160 |