| Conditions | 10 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like PascalRowAction._compute_pascal_row() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import math |
||
| 11 | @staticmethod |
||
| 12 | def _compute_pascal_row(row_index=0): |
||
| 13 | if row_index == 'a': |
||
| 14 | return False, 'This is suppose to fail don\'t worry!!' |
||
| 15 | elif row_index == 'b': |
||
| 16 | return None |
||
| 17 | elif row_index == 'complex_type': |
||
| 18 | result = PascalRowAction() |
||
| 19 | return (False, result) |
||
| 20 | elif row_index == 'c': |
||
| 21 | return False, None |
||
| 22 | elif row_index == 'd': |
||
| 23 | return 'succeeded', [1, 2, 3, 4] |
||
| 24 | elif row_index == 'e': |
||
| 25 | return [1, 2] |
||
| 26 | elif row_index == 5: |
||
| 27 | return [math.factorial(row_index) / |
||
| 28 | (math.factorial(i) * math.factorial(row_index - i)) |
||
| 29 | for i in range(row_index + 1)] |
||
| 30 | else: |
||
| 31 | return True, [math.factorial(row_index) / |
||
| 32 | (math.factorial(i) * math.factorial(row_index - i)) |
||
| 33 | for i in range(row_index + 1)] |
||
| 34 |