| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 60 | public function init() |
||
| 61 | { |
||
| 62 | parent::init(); |
||
| 63 | self::$plugin = $this; |
||
| 64 | |||
| 65 | // Components |
||
| 66 | |||
| 67 | $this->setComponents([ |
||
| 68 | 'twitter' => \dukt\twitter\services\Twitter::class, |
||
| 69 | 'accounts' => \dukt\twitter\services\Accounts::class, |
||
| 70 | 'api' => \dukt\twitter\services\Api::class, |
||
| 71 | 'cache' => \dukt\twitter\services\Cache::class, |
||
| 72 | 'oauth' => \dukt\twitter\services\Oauth::class, |
||
| 73 | 'publish' => \dukt\twitter\services\Publish::class, |
||
| 74 | ]); |
||
| 75 | |||
| 76 | |||
| 77 | // Events |
||
| 78 | |||
| 79 | Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(RegisterUrlRulesEvent $event) { |
||
| 80 | $rules = [ |
||
| 81 | 'twitter/settings' => 'twitter/settings/index', |
||
| 82 | 'twitter/settings/oauth' => 'twitter/settings/oauth', |
||
| 83 | ]; |
||
| 84 | |||
| 85 | $event->rules = array_merge($event->rules, $rules); |
||
| 86 | }); |
||
| 87 | |||
| 88 | Event::on(Dashboard::class, Dashboard::EVENT_REGISTER_WIDGET_TYPES, function(RegisterComponentTypesEvent $event) { |
||
| 89 | $event->types[] = SearchWidget::class; |
||
| 90 | }); |
||
| 91 | |||
| 92 | Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function(RegisterComponentTypesEvent $event) { |
||
| 93 | $event->types[] = TweetField::class; |
||
| 94 | }); |
||
| 95 | |||
| 96 | Event::on(ClearCaches::class, ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, function(RegisterCacheOptionsEvent $event) { |
||
| 97 | $event->options[] = [ |
||
| 98 | 'key' => 'twitter-caches', |
||
| 99 | 'label' => Craft::t('twitter', 'Twitter caches'), |
||
| 100 | 'action' => Craft::$app->path->getRuntimePath().'/twitter' |
||
| 101 | ]; |
||
| 102 | }); |
||
| 103 | |||
| 104 | Event::on(CraftVariable::class, CraftVariable::EVENT_INIT, function(Event $event) { |
||
| 105 | /** @var CraftVariable $variable */ |
||
| 106 | $variable = $event->sender; |
||
| 107 | $variable->set('twitter', TwitterVariable::class); |
||
| 108 | }); |
||
| 109 | |||
| 110 | |||
| 111 | // Twig extension |
||
| 112 | |||
| 113 | Craft::$app->view->registerTwigExtension(new Extension()); |
||
| 114 | } |
||
| 170 |