Conditions | 11 |
Paths | 92 |
Total Lines | 38 |
Code Lines | 27 |
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 |
||
51 | { |
||
52 | $txConfig = TxConfig::create($transactionOptions); |
||
53 | $this->stmtExec->rawCommand('SET SESSION CHARACTERISTICS AS TRANSACTION ' . $txConfig->toSql()); |
||
54 | } |
||
55 | |||
56 | View Code Duplication | public function commitPreparedTransaction(string $name) |
|
|
|||
57 | { |
||
58 | if ($this->inTransaction()) { |
||
59 | throw new InvalidStateException('Cannot commit a prepared transaction while inside another transaction.'); |
||
60 | } |
||
61 | |||
62 | $this->stmtExec->rawCommand("COMMIT PREPARED {$this->quoteString($name)}"); |
||
63 | $this->notifyPreparedTransactionCommit($name); |
||
64 | } |
||
65 | |||
66 | View Code Duplication | public function rollbackPreparedTransaction(string $name) |
|
67 | { |
||
68 | if ($this->inTransaction()) { |
||
69 | throw new InvalidStateException('Cannot rollback a prepared transaction while inside another transaction.'); |
||
70 | } |
||
71 | |||
72 | $this->stmtExec->rawCommand("ROLLBACK PREPARED {$this->quoteString($name)}"); |
||
73 | $this->notifyPreparedTransactionRollback($name); |
||
74 | } |
||
75 | |||
76 | public function listPreparedTransactions(): IQueryResult |
||
77 | { |
||
78 | return $this->stmtExec->rawQuery('SELECT * FROM pg_catalog.pg_prepared_xacts'); |
||
79 | } |
||
80 | |||
81 | private function quoteString(string $str) |
||
82 | { |
||
83 | static $stringSerializer = null; |
||
84 | if ($stringSerializer === null) { |
||
85 | $stringSerializer = new StringType('pg_catalog', 'text'); |
||
86 | } |
||
87 | return $stringSerializer->serializeValue($str); |
||
88 | } |
||
89 | |||
175 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.