| Conditions | 8 |
| Paths | 17 |
| Total Lines | 55 |
| Code Lines | 39 |
| 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 |
||
| 74 | public function updateSentVerificationStatus($batchSize = 1) |
||
| 75 | { |
||
| 76 | $count = $this->sentVerificationRepo->countPendingUpdateSentVerification(); |
||
| 77 | |||
| 78 | if ($count === 0) { |
||
| 79 | $this->comment('No messages pending update.'); |
||
| 80 | |||
| 81 | return []; |
||
| 82 | } |
||
| 83 | |||
| 84 | $query = $this->sentVerificationRepo->getPendingUpdateSentVerificationQuery(); |
||
| 85 | $sentVerifications = $query->iterate(); |
||
| 86 | |||
| 87 | $this->em->getConnection() ? $this->em->getConnection()->getConfiguration()->setSQLLogger(null) : null; |
||
| 88 | gc_enable(); |
||
| 89 | $this->progressStart($count); |
||
| 90 | $transactionsUpdated = []; |
||
| 91 | foreach ($sentVerifications as $row) { |
||
| 92 | /** @var SentVerificationInterface $sentVerification */ |
||
| 93 | $sentVerification = $row[0]; |
||
| 94 | $event = $this->getStatus($sentVerification->getTransactionId()); |
||
| 95 | if (false === $event->isUpdated()) { |
||
| 96 | $this->progressAdvance(1); |
||
| 97 | unset($event); |
||
| 98 | unset($sentVerification); |
||
| 99 | gc_collect_cycles(); |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | $deliveredAt = $event->getDeliveredAt(); |
||
| 104 | $sentVerification->setActuallySentAt($event->getSentAt()) |
||
| 105 | ->setDeliveredAt($deliveredAt) |
||
| 106 | ->setFinished($deliveredAt instanceof \DateTime || $event->getDeliveryStatus()->isFinal()); |
||
| 107 | $transactionsUpdated[] = $sentVerification->getTransactionId(); |
||
| 108 | unset($event); |
||
| 109 | unset($sentVerification); |
||
| 110 | if ((count($transactionsUpdated) % $batchSize) === 0) { |
||
| 111 | $this->em->flush(); |
||
| 112 | $this->em->clear(); |
||
| 113 | gc_collect_cycles(); |
||
| 114 | } |
||
| 115 | $this->progressAdvance(1); |
||
| 116 | } |
||
| 117 | $this->em->flush(); |
||
| 118 | $this->em->clear(); |
||
| 119 | $this->progressFinish(); |
||
| 120 | |||
| 121 | $countUpdated = count($transactionsUpdated); |
||
| 122 | $this->comment("Updated {$countUpdated} transactions."); |
||
| 123 | |||
| 124 | if ($countUpdated === 0) { |
||
| 125 | $this->comment("It's possible the SMS-sending service you are using doesn't implement status updates."); |
||
| 126 | } |
||
| 127 | |||
| 128 | return $transactionsUpdated; |
||
| 129 | } |
||
| 221 |