| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 38 |
| 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 |
||
| 50 | public function testTriggers(): void |
||
| 51 | { |
||
| 52 | $account1 = 10096; |
||
| 53 | $account2 = 10037; |
||
| 54 | $account3 = 10085; |
||
| 55 | $account4 = 10025; |
||
| 56 | |||
| 57 | $this->assertAccountBalance($account1, 5000, 'initial balance'); |
||
| 58 | $this->assertAccountBalance($account2, 10000, 'initial balance'); |
||
| 59 | $this->assertAccountBalance($account3, 1250, 'initial balance'); |
||
| 60 | $this->assertAccountBalance($account4, 818750, 'initial balance'); |
||
| 61 | |||
| 62 | $connection = $this->getEntityManager()->getConnection(); |
||
| 63 | $connection->insert('transaction_line', [ |
||
| 64 | 'transaction_id' => 8000, |
||
| 65 | 'debit_id' => $account1, |
||
| 66 | 'credit_id' => $account2, |
||
| 67 | 'balance' => 500, |
||
| 68 | ]); |
||
| 69 | |||
| 70 | $id = $connection->lastInsertId(); |
||
| 71 | |||
| 72 | $this->assertAccountBalance($account1, 4500, 'balance should be reduced when line is inserted'); |
||
| 73 | $this->assertAccountBalance($account2, 10500, 'balance should be increased when line is inserted'); |
||
| 74 | |||
| 75 | $count = $connection->update('transaction_line', |
||
| 76 | [ |
||
| 77 | 'balance' => 4000, |
||
| 78 | ], |
||
| 79 | [ |
||
| 80 | 'id' => $id, |
||
| 81 | ] |
||
| 82 | ); |
||
| 83 | self::assertSame(1, $count); |
||
| 84 | $this->assertAccountBalance($account1, 1000, 'balance should be reduced even more after update'); |
||
| 85 | $this->assertAccountBalance($account2, 14000, 'balance should be increased even more after update'); |
||
| 86 | |||
| 87 | $count = $connection->update('transaction_line', |
||
| 88 | [ |
||
| 89 | 'debit_id' => $account3, |
||
| 90 | 'credit_id' => $account4, |
||
| 91 | ], |
||
| 92 | [ |
||
| 93 | 'id' => $id, |
||
| 94 | ] |
||
| 95 | ); |
||
| 96 | self::assertSame(1, $count); |
||
| 97 | $this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion'); |
||
| 98 | $this->assertAccountBalance($account2, 10000, 'balance should be restored to its original value after deletion'); |
||
| 99 | $this->assertAccountBalance($account3, 5250, 'balance should be increased after swapped account'); |
||
| 100 | $this->assertAccountBalance($account4, 814750, 'balance should be reduced after swapped account'); |
||
| 101 | |||
| 102 | $count = $connection->delete('transaction_line', ['id' => $id]); |
||
| 103 | self::assertSame(1, $count); |
||
| 104 | $this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion'); |
||
| 105 | $this->assertAccountBalance($account2, 10000, 'balance should be restored to its original value after deletion'); |
||
| 106 | $this->assertAccountBalance($account3, 1250, 'balance should be restored to its original value after deletion'); |
||
| 107 | $this->assertAccountBalance($account4, 818750, 'balance should be restored to its original value after deletion'); |
||
| 108 | } |
||
| 146 |