| Conditions | 12 |
| Total Lines | 47 |
| Code Lines | 25 |
| Lines | 47 |
| Ratio | 100 % |
| Tests | 25 |
| 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 | """ |
||
| 30 | 1 | @staticmethod |
|
| 31 | 1 | def relation(x_start, x_end, y_start, y_end): |
|
| 32 | """ |
||
| 33 | Returns the relation between two intervals. |
||
| 34 | |||
| 35 | :param int x_start: The start point of the first interval. |
||
| 36 | :param int x_end: The end point of the first interval. |
||
| 37 | :param int y_start: The start point of the second interval. |
||
| 38 | :param int y_end: The end point of the second interval. |
||
| 39 | |||
| 40 | :rtype: int|None |
||
| 41 | """ |
||
| 42 | |||
| 43 | 1 | if (x_end - x_start) < 0 or (y_end - y_start) < 0: |
|
| 44 | 1 | return None |
|
| 45 | |||
| 46 | 1 | diff_end = y_end - x_end |
|
| 47 | |||
| 48 | 1 | if diff_end < 0: |
|
| 49 | 1 | return -Allen.relation(y_start, y_end, x_start, x_end) |
|
| 50 | |||
| 51 | 1 | diff_start = y_start - x_start |
|
| 52 | 1 | gab = y_start - x_end |
|
| 53 | |||
| 54 | 1 | if diff_end == 0: |
|
| 55 | 1 | if diff_start == 0: |
|
| 56 | 1 | return Allen.X_EQUAL_Y |
|
| 57 | |||
| 58 | 1 | if diff_start < 0: |
|
| 59 | 1 | return Allen.X_FINISHES_Y |
|
| 60 | |||
| 61 | 1 | return Allen.X_FINISHES_Y_INVERSE |
|
| 62 | |||
| 63 | 1 | if gab > 1: |
|
| 64 | 1 | return Allen.X_BEFORE_Y |
|
| 65 | |||
| 66 | 1 | if gab == 1: |
|
| 67 | 1 | return Allen.X_MEETS_Y |
|
| 68 | |||
| 69 | 1 | if diff_start > 0: |
|
| 70 | 1 | return Allen.X_OVERLAPS_WITH_Y |
|
| 71 | |||
| 72 | 1 | if diff_start == 0: |
|
| 73 | 1 | return Allen.X_STARTS_Y |
|
| 74 | |||
| 75 | 1 | if diff_start < 0: |
|
| 76 | 1 | return Allen.X_DURING_Y |
|
| 77 | |||
| 79 |