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