| Conditions | 12 |
| Total Lines | 45 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 12 |
| Changes | 0 | ||
Complex classes like etlt.helper.Allen.Allen.relation() 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 | 1 | from typing import Optional |
|
| 24 | @staticmethod |
||
| 25 | def relation(x_start: int, x_end: int, y_start: int, y_end: int) -> Optional[int]: |
||
| 26 | """ |
||
| 27 | Returns the relation between two intervals. |
||
| 28 | |||
| 29 | :param x_start: The start point of the first interval. |
||
| 30 | :param x_end: The end point of the first interval. |
||
| 31 | :param y_start: The start point of the second interval. |
||
| 32 | :param y_end: The end point of the second interval. |
||
| 33 | """ |
||
| 34 | 1 | ||
| 35 | 1 | if (x_end - x_start) < 0 or (y_end - y_start) < 0: |
|
| 36 | return None |
||
| 37 | 1 | ||
| 38 | diff_end = y_end - x_end |
||
| 39 | 1 | ||
| 40 | 1 | if diff_end < 0: |
|
| 41 | return -Allen.relation(y_start, y_end, x_start, x_end) |
||
| 42 | 1 | ||
| 43 | 1 | diff_start = y_start - x_start |
|
| 44 | gab = y_start - x_end |
||
| 45 | 1 | ||
| 46 | 1 | if diff_end == 0: |
|
| 47 | 1 | if diff_start == 0: |
|
| 48 | return Allen.X_EQUAL_Y |
||
| 49 | 1 | ||
| 50 | 1 | if diff_start < 0: |
|
| 51 | return Allen.X_FINISHES_Y |
||
| 52 | 1 | ||
| 53 | return Allen.X_FINISHES_Y_INVERSE |
||
| 54 | 1 | ||
| 55 | 1 | if gab > 1: |
|
| 56 | return Allen.X_BEFORE_Y |
||
| 57 | 1 | ||
| 58 | 1 | if gab == 1: |
|
| 59 | return Allen.X_MEETS_Y |
||
| 60 | 1 | ||
| 61 | 1 | if diff_start > 0: |
|
| 62 | return Allen.X_OVERLAPS_WITH_Y |
||
| 63 | 1 | ||
| 64 | 1 | if diff_start == 0: |
|
| 65 | return Allen.X_STARTS_Y |
||
| 66 | 1 | ||
| 67 | 1 | if diff_start < 0: |
|
| 68 | return Allen.X_DURING_Y |
||
| 69 | |||
| 71 |