Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 35 |
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 |
||
113 | private function progressivePriceProvider(): Generator |
||
114 | { |
||
115 | yield 'Simple case' => [ |
||
116 | 'thresholds' => [ |
||
117 | ['price' => '0.0085', 'currency' => 'EUR', 'quantity' => '0', 'unit' => 'mbps'], |
||
118 | ['price' => '0.0080', 'currency' => 'EUR', 'quantity' => '500', 'unit' => 'mbps'], |
||
119 | ['price' => '0.0075', 'currency' => 'EUR', 'quantity' => '600', 'unit' => 'mbps'], |
||
120 | ['price' => '0.0070', 'currency' => 'EUR', 'quantity' => '700', 'unit' => 'mbps'], |
||
121 | ['price' => '0.0065', 'currency' => 'EUR', 'quantity' => '800', 'unit' => 'mbps'], |
||
122 | ], |
||
123 | 'money' => 594, |
||
124 | 'price' => '0.0085', |
||
125 | ]; |
||
126 | |||
127 | yield 'Different prices for the same quantity – take higher price' => [ |
||
128 | 'thresholds' => [ |
||
129 | ['price' => '6', 'currency' => 'EUR', 'quantity' => '0', 'unit' => 'mbps'], |
||
130 | ['price' => '4', 'currency' => 'EUR', 'quantity' => '100', 'unit' => 'mbps'], // Here the qty is the same |
||
131 | ['price' => '5', 'currency' => 'EUR', 'quantity' => '0.1', 'unit' => 'gbps'], // as here, despite units are different |
||
132 | ['price' => '3', 'currency' => 'EUR', 'quantity' => '200', 'unit' => 'mbps'], |
||
133 | ], |
||
134 | 'money' => 266000, |
||
135 | 'price' => '6', |
||
136 | |||
137 | // 100mbps * 6 = 600 |
||
138 | // 100mbps * 5 = 500 |
||
139 | // 520mbps * 3 = 1560 |
||
140 | // = 2660 |
||
141 | ]; |
||
142 | |||
143 | yield 'Bill without prepaid amount' => [ |
||
144 | 'thresholds' => [ |
||
145 | ['price' => '6', 'currency' => 'EUR', 'quantity' => '100', 'unit' => 'mbps'], |
||
146 | ['price' => '5', 'currency' => 'EUR', 'quantity' => '200', 'unit' => 'mbps'], |
||
147 | ['price' => '4', 'currency' => 'EUR', 'quantity' => '300', 'unit' => 'mbps'], |
||
148 | ['price' => '3', 'currency' => 'EUR', 'quantity' => '400', 'unit' => 'mbps'], |
||
149 | ], |
||
150 | 'money' => 306000, |
||
151 | 'price' => '6', |
||
152 | 'prepaid' => '0', |
||
153 | |||
154 | // 100mbps * 6 = 600 // No prepaid, fully billed |
||
155 | // + 100mbps * 6 = 600 |
||
156 | // + 100mbps * 5 = 500 |
||
157 | // + 100mbps * 4 = 400 |
||
158 | // + 320mbps * 3 = 960 |
||
159 | // = 720mbps = 3060 |
||
160 | ]; |
||
161 | |||
162 | yield 'Bill with prepaid amount' => [ |
||
163 | 'thresholds' => [ |
||
164 | ['price' => '1', 'currency' => 'EUR', 'quantity' => '20', 'unit' => 'mbps'], |
||
165 | ['price' => '0.9', 'currency' => 'EUR', 'quantity' => '30', 'unit' => 'mbps'], |
||
166 | ['price' => '0.856', 'currency' => 'EUR', 'quantity' => '0.1', 'unit' => 'gbps'], |
||
167 | ['price' => '0.5521', 'currency' => 'EUR', 'quantity' => '130.5', 'unit' => 'mbps'], |
||
168 | ], |
||
169 | 'result' => 43487, |
||
170 | 'price' => '1.03', |
||
171 | 'prepaid' => '10', |
||
172 | |||
185 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.