Conditions | 4 |
Paths | 8 |
Total Lines | 60 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
88 | public function handle() |
||
89 | { |
||
90 | // Is the form being submitted to us? |
||
91 | if ($this->request->is_set_post('submit')) |
||
92 | { |
||
93 | $this->check_form_on_submit(); |
||
94 | |||
95 | // Set the options the user configured |
||
96 | $this->config->set('dark1_unc_all_notify_expire_days', $this->request->variable('dark1_unc_all_notify_expire_days', 0)); |
||
97 | $this->config->set('dark1_unc_auto_prune_notify_enable', $this->request->variable('dark1_unc_auto_prune_notify_enable', 0)); |
||
98 | $this->config->set('dark1_unc_auto_prune_notify_gc', ($this->request->variable('dark1_unc_auto_prune_notify_gc', 0)) * 86400); |
||
99 | |||
100 | $this->success_form_on_submit(); |
||
101 | } |
||
102 | |||
103 | // Run Cron Task |
||
104 | if ($this->request->is_set_post('runcrontask')) |
||
105 | { |
||
106 | $this->check_form_on_submit(); |
||
107 | |||
108 | $cron_task = $this->cron_manager->find_task('dark1.usernotificationcontrol.cron.auto_prune_notify'); |
||
109 | $cron_task->run(); |
||
110 | |||
111 | $this->success_form_on_submit(); |
||
112 | } |
||
113 | |||
114 | $this->language->add_lang('acp/board'); |
||
115 | $main_adm_path = $this->phpbb_root_path . $this->phpbb_adm_relative_path . 'index.' . $this->php_ext; |
||
116 | $read_expire_link = append_sid($main_adm_path, 'i=acp_board&mode=load').'#read_notification_expire_days'; |
||
117 | |||
118 | $days = $this->config['read_notification_expire_days'] + $this->config['dark1_unc_all_notify_expire_days']; |
||
119 | $timestamp = time() - ($days * 86400); |
||
120 | foreach (['all' => '> 0', 'exp' => '< '.$timestamp, 'rem' => '>= '.$timestamp] as $key => $value) |
||
121 | { |
||
122 | $sql = 'SELECT `notification_read`, COUNT(*) AS `count`' . |
||
123 | ' FROM ' . NOTIFICATIONS_TABLE . |
||
124 | ' WHERE `notification_time` ' . (string) $value . |
||
125 | ' GROUP BY `notification_read`' . |
||
126 | ' ORDER BY `notification_read` ASC'; |
||
127 | $result = $this->db->sql_query($sql); |
||
128 | $rows = $this->db->sql_fetchrowset($result); |
||
129 | $this->db->sql_freeresult($result); |
||
130 | |||
131 | $this->template->assign_block_vars('stats', [ |
||
132 | 'TYPE' => $this->language->lang('ACP_UNC_STAT_' . strtoupper($key)), |
||
133 | 'UNREAD' => (int) $rows[0]['count'], |
||
134 | 'READ' => (int) $rows[1]['count'], |
||
135 | ]); |
||
136 | } |
||
137 | |||
138 | // Set output variables for display in the template |
||
139 | $this->template->assign_vars([ |
||
140 | 'UNC_READ_EXPIRE' => $this->config['read_notification_expire_days'], |
||
141 | 'UNC_READ_EXPIRE_LINK' => $read_expire_link, |
||
142 | 'UNC_ALL_EXPIRE' => $this->config['dark1_unc_all_notify_expire_days'], |
||
143 | 'UNC_TOTAL_EXPIRE' => $days, |
||
144 | 'UNC_ENABLE_CRON' => $this->config['dark1_unc_auto_prune_notify_enable'], |
||
145 | 'UNC_CRON_INTERVAL' => ($this->config['dark1_unc_auto_prune_notify_gc'] / 86400), |
||
146 | 'UNC_CRON_LAST_RUN' => $this->user->format_date($this->config['dark1_unc_auto_prune_notify_last_gc'], self::TIME_FORMAT, true), |
||
147 | 'UNC_CRON_NEXT_RUN' => $this->user->format_date($this->config['dark1_unc_auto_prune_notify_last_gc'] + $this->config['dark1_unc_auto_prune_notify_gc'], self::TIME_FORMAT, true), |
||
148 | ]); |
||
151 |