| Conditions | 10 |
| Paths | 68 |
| Total Lines | 35 |
| Code Lines | 26 |
| 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 |
||
| 18 | public function process() |
||
| 19 | { |
||
| 20 | $pauser = \App\Pauser::getInstance('MailAccountVerification'); |
||
| 21 | $lastId = (int) $pauser->getValue(); |
||
| 22 | $deactivationTime = \App\Mail::getConfig('scanner', 'deactivation_time'); |
||
| 23 | |||
| 24 | $queryGenerator = (new \App\QueryGenerator('MailAccount')) |
||
| 25 | ->setFields(['id']) |
||
| 26 | ->addCondition('mailaccount_status', \App\Mail\Account::STATUS_LOCKED, 'e'); |
||
| 27 | if ($lastId) { |
||
| 28 | $queryGenerator->addCondition('id', $lastId, 'a'); |
||
| 29 | } |
||
| 30 | $dataReader = $queryGenerator->createQuery()->createCommand()->query(); |
||
| 31 | $count = $dataReader->count(); |
||
| 32 | while ($recordId = $dataReader->readColumn(0)) { |
||
| 33 | $pauser->setValue((string) $recordId); |
||
| 34 | $mailAccount = \App\Mail\Account::getInstanceById($recordId); |
||
| 35 | try { |
||
| 36 | $mailbox = $mailAccount->openImap(); |
||
| 37 | if ($mailbox->isConnected()) { |
||
| 38 | $mailAccount->unlock(); |
||
| 39 | } |
||
| 40 | } catch (\Throwable $th) { |
||
| 41 | $lastLogin = $mailAccount->getSource()->get('last_login') ?: $mailAccount->getSource()->get('createdtime'); |
||
| 42 | $hours = \App\Fields\DateTime::getDiff($lastLogin, date('Y-m-d H:i:s'), 'hours'); |
||
| 43 | if ((int) $hours >= (int) $deactivationTime) { |
||
| 44 | $mailAccount->deactivate($th->getMessage()); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | if ($this->checkTimeout()) { |
||
| 48 | break; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | if (!$lastId || !$count) { |
||
| 52 | $pauser->destroy(); |
||
| 53 | } |
||
| 56 |