| Conditions | 3 |
| Paths | 11 |
| Total Lines | 59 |
| Code Lines | 36 |
| 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 |
||
| 36 | public function process(AbstractCommand $command): AbstractCommand |
||
| 37 | { |
||
| 38 | $this->logger->debug( |
||
| 39 | sprintf( |
||
| 40 | 'Starting Transaction in TransactionAwarePipeline for processing command "%s"', |
||
| 41 | $command, |
||
| 42 | ), |
||
| 43 | ); |
||
| 44 | |||
| 45 | $this->middlewareConnection->beginTransaction(); |
||
| 46 | $this->gatewayConnection->beginTransaction(); |
||
| 47 | |||
| 48 | try { |
||
| 49 | $this->logger->debug(sprintf('Requesting inner pipeline to process command "%s"', $command)); |
||
| 50 | |||
| 51 | $command = $this->innerPipeline->process($command); |
||
| 52 | |||
| 53 | $this->logger->debug(sprintf('Inner pipeline processed command "%s", committing transaction', $command)); |
||
| 54 | |||
| 55 | $this->middlewareConnection->commit(); |
||
| 56 | $this->gatewayConnection->commit(); |
||
| 57 | } catch (Exception $e) { |
||
| 58 | // log at highest level if we may have a split head in the db-cluster... |
||
| 59 | if (strpos($e->getMessage(), 'ER_UNKNOWN_COM_ERROR')) { |
||
| 60 | $this->logger->emergency( |
||
| 61 | sprintf( |
||
| 62 | '[!!!] Critical Database Exception while processing command "%s": "%s"', |
||
| 63 | $command, |
||
| 64 | $e->getMessage(), |
||
| 65 | ), |
||
| 66 | ['exception' => $e], |
||
| 67 | ); |
||
| 68 | } else { |
||
| 69 | $this->logger->error( |
||
| 70 | sprintf( |
||
| 71 | 'Exception occurred while processing command "%s": "%s", rolling back transaction', |
||
| 72 | $command, |
||
| 73 | $e->getMessage(), |
||
| 74 | ), |
||
| 75 | ['exception' => $e], |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->middlewareConnection->rollBack(); |
||
| 80 | $this->gatewayConnection->rollBack(); |
||
| 81 | |||
| 82 | $this->logger->debug( |
||
| 83 | sprintf( |
||
| 84 | 'Transaction for command "%s" rolled back, re-throwing exception', |
||
| 85 | $command, |
||
| 86 | ), |
||
| 87 | ); |
||
| 88 | |||
| 89 | throw $e; |
||
| 90 | } |
||
| 91 | |||
| 92 | $this->logger->debug(sprintf('Transaction committed, done processing command "%s"', $command)); |
||
| 93 | |||
| 94 | return $command; |
||
| 95 | } |
||
| 97 |