| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 102 | 
| Code Lines | 64 | 
| 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  | 
            ||
| 41 | public function testTriggers(): void  | 
            ||
| 42 |     { | 
            ||
| 43 | $account1 = 10096;  | 
            ||
| 44 | $account2 = 10037;  | 
            ||
| 45 | $account3 = 10085;  | 
            ||
| 46 | $account4 = 10025;  | 
            ||
| 47 | |||
| 48 | $this->assertAccountBalance($account1, 5000, 'initial balance');  | 
            ||
| 49 | $this->assertAccountBalance($account2, 10000, 'initial balance');  | 
            ||
| 50 | $this->assertAccountBalance($account3, 1250, 'initial balance');  | 
            ||
| 51 | $this->assertAccountBalance($account4, 818750, 'initial balance');  | 
            ||
| 52 | |||
| 53 | $connection = $this->getEntityManager()->getConnection();  | 
            ||
| 54 |         $connection->insert('transaction_line', [ | 
            ||
| 55 | 'transaction_id' => 8000,  | 
            ||
| 56 | 'debit_id' => $account1,  | 
            ||
| 57 | 'credit_id' => $account2,  | 
            ||
| 58 | 'balance' => 500,  | 
            ||
| 59 | ]);  | 
            ||
| 60 | |||
| 61 | $id = $connection->lastInsertId();  | 
            ||
| 62 | |||
| 63 | $this->assertAccountBalance($account1, 4500, 'balance should be reduced when line is inserted');  | 
            ||
| 64 | $this->assertAccountBalance($account2, 10500, 'balance should be increased when line is inserted');  | 
            ||
| 65 | |||
| 66 | $count = $connection->update(  | 
            ||
| 67 | 'transaction_line',  | 
            ||
| 68 | [  | 
            ||
| 69 | 'balance' => 4000,  | 
            ||
| 70 | ],  | 
            ||
| 71 | [  | 
            ||
| 72 | 'id' => $id,  | 
            ||
| 73 | ]  | 
            ||
| 74 | );  | 
            ||
| 75 | self::assertSame(1, $count);  | 
            ||
| 76 | $this->assertAccountBalance($account1, 1000, 'balance should be reduced even more after update');  | 
            ||
| 77 | $this->assertAccountBalance($account2, 14000, 'balance should be increased even more after update');  | 
            ||
| 78 | |||
| 79 | $count = $connection->update(  | 
            ||
| 80 | 'transaction_line',  | 
            ||
| 81 | [  | 
            ||
| 82 | 'debit_id' => $account2,  | 
            ||
| 83 | 'credit_id' => $account1,  | 
            ||
| 84 | ],  | 
            ||
| 85 | [  | 
            ||
| 86 | 'id' => $id,  | 
            ||
| 87 | ]  | 
            ||
| 88 | );  | 
            ||
| 89 | self::assertSame(1, $count);  | 
            ||
| 90 | $this->assertAccountBalance($account1, 9000, 'balance should be twice increased after swapping both accounts');  | 
            ||
| 91 | $this->assertAccountBalance($account2, 6000, 'balance should be reduced increased after swapping both accounts');  | 
            ||
| 92 | |||
| 93 | $count = $connection->update(  | 
            ||
| 94 | 'transaction_line',  | 
            ||
| 95 | [  | 
            ||
| 96 | 'debit_id' => $account2,  | 
            ||
| 97 | 'credit_id' => null,  | 
            ||
| 98 | ],  | 
            ||
| 99 | [  | 
            ||
| 100 | 'id' => $id,  | 
            ||
| 101 | ]  | 
            ||
| 102 | );  | 
            ||
| 103 | self::assertSame(1, $count);  | 
            ||
| 104 | $this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion');  | 
            ||
| 105 | $this->assertAccountBalance($account2, 6000, 'balance should be unchanged');  | 
            ||
| 106 | |||
| 107 | $count = $connection->update(  | 
            ||
| 108 | 'transaction_line',  | 
            ||
| 109 | [  | 
            ||
| 110 | 'debit_id' => null,  | 
            ||
| 111 | 'credit_id' => $account2,  | 
            ||
| 112 | ],  | 
            ||
| 113 | [  | 
            ||
| 114 | 'id' => $id,  | 
            ||
| 115 | ]  | 
            ||
| 116 | );  | 
            ||
| 117 | self::assertSame(1, $count);  | 
            ||
| 118 | $this->assertAccountBalance($account1, 5000, 'balance should be unchanged');  | 
            ||
| 119 | $this->assertAccountBalance($account2, 14000, 'balance should be twice increased after swapping a single account');  | 
            ||
| 120 | |||
| 121 | $count = $connection->update(  | 
            ||
| 122 | 'transaction_line',  | 
            ||
| 123 | [  | 
            ||
| 124 | 'debit_id' => $account3,  | 
            ||
| 125 | 'credit_id' => $account4,  | 
            ||
| 126 | ],  | 
            ||
| 127 | [  | 
            ||
| 128 | 'id' => $id,  | 
            ||
| 129 | ]  | 
            ||
| 130 | );  | 
            ||
| 131 | self::assertSame(1, $count);  | 
            ||
| 132 | $this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion');  | 
            ||
| 133 | $this->assertAccountBalance($account2, 10000, 'balance should be restored to its original value after deletion');  | 
            ||
| 134 | $this->assertAccountBalance($account3, 5250, 'balance should be increased after swapped account');  | 
            ||
| 135 | $this->assertAccountBalance($account4, 814750, 'balance should be reduced after swapped account');  | 
            ||
| 136 | |||
| 137 |         $count = $connection->delete('transaction_line', ['id' => $id]); | 
            ||
| 138 | self::assertSame(1, $count);  | 
            ||
| 139 | $this->assertAccountBalance($account1, 5000, 'balance should be restored to its original value after deletion');  | 
            ||
| 140 | $this->assertAccountBalance($account2, 10000, 'balance should be restored to its original value after deletion');  | 
            ||
| 141 | $this->assertAccountBalance($account3, 1250, 'balance should be restored to its original value after deletion');  | 
            ||
| 142 | $this->assertAccountBalance($account4, 818750, 'balance should be restored to its original value after deletion');  | 
            ||
| 143 | }  | 
            ||
| 191 |