| Conditions | 3 |
| Paths | 11 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 65 | public function process(Command $command) |
||
| 66 | { |
||
| 67 | $this->logger->debug(sprintf( |
||
| 68 | 'Starting Transaction in TransactionAwarePipeline for processing command "%s"', |
||
| 69 | $command |
||
| 70 | )); |
||
| 71 | |||
| 72 | $this->middlewareConnection->beginTransaction(); |
||
| 73 | $this->gatewayConnection->beginTransaction(); |
||
| 74 | |||
| 75 | try { |
||
| 76 | $this->logger->debug(sprintf('Requesting inner pipeline to process command "%s"', $command)); |
||
| 77 | |||
| 78 | $command = $this->innerPipeline->process($command); |
||
| 79 | |||
| 80 | $this->logger->debug(sprintf('Inner pipeline processed command "%s", committing transaction', $command)); |
||
| 81 | |||
| 82 | $this->middlewareConnection->commit(); |
||
| 83 | $this->gatewayConnection->commit(); |
||
| 84 | } catch (\Exception $e) { |
||
| 85 | // log at highest level if we may have a split head in the db-cluster... |
||
| 86 | if (strpos($e->getMessage(), 'ER_UNKNOWN_COM_ERROR')) { |
||
| 87 | $this->logger->emergency( |
||
| 88 | sprintf( |
||
| 89 | '[!!!] Critical Database Exception while processing command "%s": "%s"', |
||
| 90 | $command, |
||
| 91 | $e->getMessage() |
||
| 92 | ), |
||
| 93 | ['exception' => $e] |
||
| 94 | ); |
||
| 95 | } else { |
||
| 96 | $this->logger->error( |
||
| 97 | sprintf( |
||
| 98 | 'Exception occurred while processing command "%s": "%s", rolling back transaction', |
||
| 99 | $command, |
||
| 100 | $e->getMessage() |
||
| 101 | ), |
||
| 102 | ['exception' => $e] |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | $this->middlewareConnection->rollBack(); |
||
| 107 | $this->gatewayConnection->rollBack(); |
||
| 108 | |||
| 109 | $this->logger->debug(sprintf( |
||
| 110 | 'Transaction for command "%s" rolled back, re-throwing exception', |
||
| 111 | $command |
||
| 112 | )); |
||
| 113 | |||
| 114 | throw $e; |
||
| 115 | } |
||
| 116 | |||
| 117 | $this->logger->debug(sprintf('Transaction committed, done processing command "%s"', $command)); |
||
| 118 | |||
| 119 | return $command; |
||
| 120 | } |
||
| 121 | } |
||
| 122 |