Conditions | 13 |
Paths | 48 |
Total Lines | 44 |
Code Lines | 33 |
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 |
||
19 | public function process() |
||
20 | { |
||
21 | $config = OSSMailScanner_Record_Model::getConfig('cron'); |
||
22 | $duration = $config['time'] ?? 0; |
||
23 | $email = $config['email'] ?? ''; |
||
24 | $dbCommand = App\Db::getInstance()->createCommand(); |
||
25 | $dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query(); |
||
26 | while ($row = $dataReader->read()) { |
||
27 | $startTime = strtotime($row['start_time']); |
||
28 | if ($duration && $email |
||
29 | && strtotime('now') > $startTime + ($duration * 60) |
||
30 | && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) { |
||
31 | $dbCommand->insert('vtiger_ossmailscanner_log_cron', ['laststart' => $startTime, 'status' => 0, 'created_time' => date('Y-m-d H:i:s')])->execute(); |
||
32 | $url = \App\Config::main('site_URL'); |
||
33 | $mailStatus = \App\Mailer::addMail([ |
||
34 | 'to' => $email, |
||
35 | 'subject' => App\Language::translate('Email_FromName', 'OSSMailScanner'), |
||
36 | 'content' => App\Language::translate('Email_Body', 'OSSMailScanner') . "\r\n<br><a href='{$url}'>{$url}</a>", |
||
37 | ]); |
||
38 | $dbCommand->update('vtiger_ossmailscanner_log_cron', ['status' => (int) $mailStatus], ['laststart' => $startTime])->execute(); |
||
39 | } |
||
40 | } |
||
41 | $dataReader->close(); |
||
42 | |||
43 | $hours = OSSMailScanner_Record_Model::getConfig('cron')['blockCheckHours'] ?? ''; |
||
44 | $hours = $hours ? explode(',', $hours) : []; |
||
45 | $query = (new \App\Db\Query())->from('roundcube_users')->where(['crm_status' => \OSSMail_Record_Model::MAIL_BOX_STATUS_BLOCKED_TEMP]); |
||
46 | $dataReader = $query->createCommand()->query(); |
||
47 | while ($account = $dataReader->read()) { |
||
48 | if (empty($account['actions'])) { |
||
49 | continue; |
||
50 | } |
||
51 | $check = true; |
||
52 | if (!empty($account['failed_login'])) { |
||
53 | $check = date('Y-m-d G', strtotime($account['failed_login'])) !== date('Y-m-d G'); |
||
54 | if ($hours && $check) { |
||
55 | $check = \in_array(date('G'), $hours); |
||
56 | } |
||
57 | } |
||
58 | if ($check) { |
||
59 | \OSSMail_Record_Model::imapConnect($account['username'], \App\Encryption::getInstance()->decrypt($account['password']), $account['mail_host'], '', false, [], $account); |
||
60 | } |
||
61 | } |
||
62 | $dataReader->close(); |
||
63 | } |
||
65 |