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