Conditions | 4 |
Paths | 4 |
Total Lines | 51 |
Code Lines | 35 |
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 |
||
42 | public function testInvoiceInitial(string $initialPrice, string $periodicPrice, array $expected): void |
||
43 | { |
||
44 | $user = new User(); |
||
45 | $user->setFirstName('John'); |
||
46 | $user->setLastName('Doe'); |
||
47 | |||
48 | $bookable = new Bookable(); |
||
49 | $bookable->setName('My bookable'); |
||
50 | $bookable->setInitialPrice($initialPrice); |
||
51 | $bookable->setPeriodicPrice($periodicPrice); |
||
52 | |||
53 | $bookableAccount = new Account(); |
||
54 | $bookableAccount->setName('Bookable account'); |
||
55 | $bookable->setCreditAccount($bookableAccount); |
||
56 | |||
57 | // Creation of booking will implicitly call the invoicer |
||
58 | $booking = new Booking(); |
||
59 | $booking->setOwner($user); |
||
60 | $booking->setBookable($bookable); |
||
61 | |||
62 | $account = $user->getAccount(); |
||
63 | |||
64 | if ($expected === []) { |
||
65 | self::assertNull($account); |
||
66 | } else { |
||
67 | $all = array_merge( |
||
68 | $account->getCreditTransactionLines()->toArray(), |
||
69 | $account->getDebitTransactionLines()->toArray() |
||
70 | ); |
||
71 | $actual = []; |
||
72 | |||
73 | /** @var TransactionLine $t */ |
||
74 | $transaction = null; |
||
75 | foreach ($all as $t) { |
||
76 | if (!$transaction) { |
||
77 | $transaction = $t->getTransaction(); |
||
78 | self::assertNotNull($transaction, 'must belong to a transaction'); |
||
79 | } else { |
||
80 | self::assertSame($transaction, $t->getTransaction(), 'all lines should belong to same transaction'); |
||
81 | } |
||
82 | |||
83 | $actual[] = [ |
||
84 | $t->getName(), |
||
85 | $t->getBookable()->getName(), |
||
86 | $t->getDebit()->getName(), |
||
87 | $t->getCredit()->getName(), |
||
88 | $t->getBalance(), |
||
89 | ]; |
||
90 | } |
||
91 | |||
92 | self::assertSame($expected, $actual); |
||
93 | } |
||
189 |