| Conditions | 4 |
| Paths | 2 |
| Total Lines | 61 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 59 | public function init() |
||
| 60 | { |
||
| 61 | parent::init(); |
||
| 62 | self::$plugin = $this; |
||
| 63 | |||
| 64 | $this->setComponents([ |
||
| 65 | 'analytics' => \dukt\analytics\services\Analytics::class, |
||
| 66 | 'apis' => \dukt\analytics\services\Apis::class, |
||
| 67 | 'cache' => \dukt\analytics\services\Cache::class, |
||
| 68 | 'geo' => \dukt\analytics\services\Geo::class, |
||
| 69 | 'metadata' => \dukt\analytics\services\Metadata::class, |
||
| 70 | 'oauth' => \dukt\analytics\services\Oauth::class, |
||
| 71 | 'reports' => \dukt\analytics\services\Reports::class, |
||
| 72 | 'views' => \dukt\analytics\services\Views::class, |
||
| 73 | ]); |
||
| 74 | |||
| 75 | Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $event) { |
||
| 76 | $rules = [ |
||
| 77 | 'analytics/settings' => 'analytics/settings/index', |
||
| 78 | 'analytics/settings/oauth' => 'analytics/settings/oauth', |
||
| 79 | 'analytics/settings/views' => 'analytics/settings/views', |
||
| 80 | 'analytics/settings/views/new' => 'analytics/settings/edit-view', |
||
| 81 | 'analytics/settings/views/<viewId:\d+>' => 'analytics/settings/edit-view', |
||
| 82 | 'analytics/settings/sites' => 'analytics/settings/sites', |
||
| 83 | 'analytics/settings/sites/<siteId:\d+>' => 'analytics/settings/edit-site', |
||
| 84 | 'analytics/utils' => 'analytics/utils/metadata', |
||
| 85 | 'analytics/utils/metadata' => 'analytics/utils/metadata', |
||
| 86 | 'analytics/tests/data-types' => 'analytics/tests/data-types', |
||
| 87 | 'analytics/tests' => 'analytics/tests/columns', |
||
| 88 | 'analytics/tests/columns' => 'analytics/tests/columns', |
||
| 89 | 'analytics/tests/column-groups' => 'analytics/tests/column-groups', |
||
| 90 | 'analytics/tests/formatting' => 'analytics/tests/formatting', |
||
| 91 | 'analytics/tests/report-widgets' => 'analytics/tests/report-widgets', |
||
| 92 | 'analytics/tests/template-variables' => 'analytics/tests/template-variables', |
||
| 93 | 'analytics/api4' => 'analytics/api4', |
||
| 94 | ]; |
||
| 95 | |||
| 96 | $event->rules = array_merge($event->rules, $rules); |
||
| 97 | }); |
||
| 98 | |||
| 99 | Event::on(Dashboard::class, Dashboard::EVENT_REGISTER_WIDGET_TYPES, function(RegisterComponentTypesEvent $event) { |
||
| 100 | $event->types[] = Ecommerce::class; |
||
| 101 | $event->types[] = Realtime::class; |
||
| 102 | $event->types[] = Report::class; |
||
| 103 | }); |
||
| 104 | |||
| 105 | Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function(RegisterComponentTypesEvent $event) { |
||
| 106 | $event->types[] = ReportField::class; |
||
| 107 | }); |
||
| 108 | |||
| 109 | Event::on(CraftVariable::class, CraftVariable::EVENT_INIT, function(Event $event) { |
||
| 110 | /** @var CraftVariable $variable */ |
||
| 111 | $variable = $event->sender; |
||
| 112 | $variable->set('analytics', AnalyticsVariable::class); |
||
| 113 | }); |
||
| 114 | |||
| 115 | if ($this->isInstalled && !Craft::$app->getRequest()->getIsConsoleRequest() && Craft::$app->getRequest()->getIsCpRequest()) { |
||
| 116 | Craft::$app->getView()->registerAssetBundle(AnalyticsAsset::class); |
||
| 117 | } |
||
| 118 | |||
| 119 | Craft::setAlias('@analyticsLib', __DIR__ . '/../lib'); |
||
| 120 | } |
||
| 145 |