| Conditions | 1 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 62 |
| 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 |
||
| 138 | private function progressivePriceProvider(): Generator |
||
| 139 | { |
||
| 140 | yield 'Simple case' => [ |
||
| 141 | 'thresholds' => [ |
||
| 142 | ['price' => '0.0085', 'currency' => 'EUR', 'quantity' => '0', 'unit' => 'mbps'], |
||
| 143 | ['price' => '0.0080', 'currency' => 'EUR', 'quantity' => '500', 'unit' => 'mbps'], |
||
| 144 | ['price' => '0.0075', 'currency' => 'EUR', 'quantity' => '600', 'unit' => 'mbps'], |
||
| 145 | ['price' => '0.0070', 'currency' => 'EUR', 'quantity' => '700', 'unit' => 'mbps'], |
||
| 146 | ['price' => '0.0065', 'currency' => 'EUR', 'quantity' => '800', 'unit' => 'mbps'], |
||
| 147 | ], |
||
| 148 | 'money' => 594, |
||
| 149 | 'price' => '0.0085', |
||
| 150 | 'prepaid' => '0', |
||
| 151 | 'trace' => [ |
||
| 152 | '0mbps * 0.0065 = 0.00', |
||
| 153 | '20mbps * 0.0070 = 0.14', |
||
| 154 | '100mbps * 0.0075 = 0.75', |
||
| 155 | '100mbps * 0.0080 = 0.80', |
||
| 156 | '500mbps * 0.0085 = 4.25', |
||
| 157 | '0mbps * 0.01 = 0.00', |
||
| 158 | ], |
||
| 159 | ]; |
||
| 160 | |||
| 161 | yield 'Different prices for the same quantity – take higher price' => [ |
||
| 162 | 'thresholds' => [ |
||
| 163 | ['price' => '6', 'currency' => 'EUR', 'quantity' => '0', 'unit' => 'mbps'], |
||
| 164 | ['price' => '4', 'currency' => 'EUR', 'quantity' => '100', 'unit' => 'mbps'], // Here the qty is the same |
||
| 165 | ['price' => '5000', 'currency' => 'EUR', 'quantity' => '0.1', 'unit' => 'gbps'], // as here, despite units are different |
||
| 166 | ['price' => '3', 'currency' => 'EUR', 'quantity' => '200', 'unit' => 'mbps'], |
||
| 167 | ], |
||
| 168 | 'money' => 266000, |
||
| 169 | 'price' => '6', |
||
| 170 | 'prepaid' => '0', |
||
| 171 | 'trace' => [ |
||
| 172 | '520mbps * 3 = 1,560.00', |
||
| 173 | '0.1gbps * 5000 = 500.00', |
||
| 174 | '0mbps * 4 = 0.00', |
||
| 175 | '100mbps * 6 = 600.00', |
||
| 176 | '0mbps * 6 = 0.00', |
||
| 177 | ], |
||
| 178 | ]; |
||
| 179 | |||
| 180 | yield 'Bill without prepaid amount' => [ |
||
| 181 | 'thresholds' => [ |
||
| 182 | ['price' => '6', 'currency' => 'EUR', 'quantity' => '100', 'unit' => 'mbps'], |
||
| 183 | ['price' => '5', 'currency' => 'EUR', 'quantity' => '200', 'unit' => 'mbps'], |
||
| 184 | ['price' => '4', 'currency' => 'EUR', 'quantity' => '300', 'unit' => 'mbps'], |
||
| 185 | ['price' => '3', 'currency' => 'EUR', 'quantity' => '400', 'unit' => 'mbps'], |
||
| 186 | ], |
||
| 187 | 'money' => 306000, |
||
| 188 | 'price' => '6', |
||
| 189 | 'prepaid' => '0', |
||
| 190 | 'trace' => [ |
||
| 191 | '320mbps * 3 = 960.00', |
||
| 192 | '100mbps * 4 = 400.00', |
||
| 193 | '100mbps * 5 = 500.00', |
||
| 194 | '100mbps * 6 = 600.00', |
||
| 195 | '100mbps * 6 = 600.00', |
||
| 196 | ], |
||
| 197 | ]; |
||
| 198 | |||
| 199 | yield 'Bill with prepaid amount' => [ |
||
| 200 | 'thresholds' => [ |
||
| 201 | ['price' => '1', 'currency' => 'EUR', 'quantity' => '20', 'unit' => 'mbps'], |
||
| 202 | ['price' => '0.9', 'currency' => 'EUR', 'quantity' => '30', 'unit' => 'mbps'], |
||
| 203 | ['price' => '856.00', 'currency' => 'EUR', 'quantity' => '0.1', 'unit' => 'gbps'], |
||
| 204 | ['price' => '0.5521', 'currency' => 'EUR', 'quantity' => '130.5', 'unit' => 'mbps'], |
||
| 205 | ], |
||
| 206 | 'result' => 43487, |
||
| 207 | 'price' => '1.03', |
||
| 208 | 'prepaid' => '10', |
||
| 209 | 'trace' => [ |
||
| 210 | '589.5mbps * 0.5521 = 325.46', |
||
| 211 | '0.0305gbps * 856.00 = 26.11', |
||
| 212 | '70mbps * 0.9 = 63.00', |
||
| 213 | '10mbps * 1 = 10.00', |
||
| 214 | '10mbps * 1.03 = 10.30', |
||
| 215 | ], |
||
| 219 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.