| Conditions | 7 |
| Paths | 9 |
| Total Lines | 51 |
| Code Lines | 33 |
| 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 |
||
| 63 | public function updateSentVerificationStatus($batchSize = 1) |
||
| 64 | { |
||
| 65 | $count = $this->sentVerificationRepo->countPendingUpdateSentVerification(); |
||
| 66 | |||
| 67 | if ($count === 0) { |
||
| 68 | $this->comment('No messages pending update.'); |
||
| 69 | |||
| 70 | return []; |
||
| 71 | } |
||
| 72 | |||
| 73 | $query = $this->sentVerificationRepo->getPendingUpdateSentVerificationQuery(); |
||
| 74 | $sentVerifications = $query->iterate(); |
||
| 75 | |||
| 76 | $this->progressStart($count); |
||
| 77 | $transactionsUpdated = []; |
||
| 78 | foreach ($sentVerifications as $row) { |
||
| 79 | /** @var SentVerificationInterface $sentVerification */ |
||
| 80 | $sentVerification = $row[0]; |
||
| 81 | $status = $this->getStatus($sentVerification->getTransactionId()); |
||
| 82 | |||
| 83 | if (false === $status->isUpdated()) { |
||
| 84 | $this->progressAdvance(1); |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | |||
| 88 | $deliveredAt = $status->getDeliveredAt(); |
||
| 89 | $sentVerification->setActuallySentAt($status->getSentAt()) |
||
| 90 | ->setDeliveredAt($deliveredAt) |
||
| 91 | ->setFinished( |
||
| 92 | $deliveredAt instanceof \DateTime || DeliveryStatus::isFinal($status->getDeliveryStatus()) |
||
| 93 | ); |
||
| 94 | $transactionsUpdated[] = $sentVerification->getTransactionId(); |
||
| 95 | if ((count($transactionsUpdated) % $batchSize) === 0) { |
||
| 96 | $this->em->flush(); |
||
| 97 | $this->em->clear(); |
||
| 98 | } |
||
| 99 | $this->progressAdvance(1); |
||
| 100 | } |
||
| 101 | $this->em->flush(); |
||
| 102 | $this->em->clear(); |
||
| 103 | $this->progressFinish(); |
||
| 104 | |||
| 105 | $countUpdated = count($transactionsUpdated); |
||
| 106 | $this->comment("Updated {$countUpdated} transactions."); |
||
| 107 | |||
| 108 | if ($countUpdated === 0) { |
||
| 109 | $this->comment("It's possible the SMS-sending service you are using doesn't implement status updates."); |
||
| 110 | } |
||
| 111 | |||
| 112 | return $transactionsUpdated; |
||
| 113 | } |
||
| 114 | |||
| 205 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.