| Conditions | 10 |
| Total Lines | 50 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like paytext.paytext.PaymentText.clean() 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 | # pyre-strict |
||
| 18 | def clean(self) -> None: |
||
| 19 | parts: List[str] = self.text.split() |
||
| 20 | |||
| 21 | pattern = compile_regex(r'\*\d{4}') |
||
| 22 | |||
| 23 | try: |
||
| 24 | if pattern.match(parts[0]): |
||
|
1 ignored issue
–
show
|
|||
| 25 | del parts[0] |
||
| 26 | except IndexError: |
||
| 27 | return |
||
| 28 | |||
| 29 | pattern = compile_regex(r'\d{2}\.\d{2}') |
||
| 30 | |||
| 31 | if pattern.match(parts[0]): |
||
| 32 | del parts[0] |
||
| 33 | |||
| 34 | currency: Any = iso4217parse.by_alpha3(parts[0]) |
||
| 35 | |||
| 36 | if isinstance(currency, iso4217parse.Currency): |
||
|
1 ignored issue
–
show
|
|||
| 37 | del parts[0] |
||
| 38 | del parts[0] |
||
| 39 | |||
| 40 | pattern = compile_regex(r'\d{1}\.\d{4}') |
||
| 41 | |||
| 42 | if pattern.match(parts[-1]): |
||
| 43 | del parts[-1] |
||
| 44 | del parts[-1] |
||
| 45 | |||
| 46 | pattern = compile_regex(r'\d{2}\.\d{2}\.\d{2}') |
||
| 47 | |||
| 48 | if pattern.match(parts[-1]): |
||
| 49 | del parts[-1] |
||
| 50 | |||
| 51 | pattern = compile_regex(r'.+:') |
||
| 52 | |||
| 53 | if pattern.match(parts[-1]): |
||
| 54 | del parts[-1] |
||
| 55 | |||
| 56 | pattern = compile_regex(r'\d+,\d{2}') |
||
| 57 | |||
| 58 | if pattern.match(parts[-1]): |
||
| 59 | del parts[-1] |
||
| 60 | |||
| 61 | currency: Any = iso4217parse.by_alpha3(parts[-1]) |
||
| 62 | if isinstance(currency, iso4217parse.Currency): |
||
| 63 | del parts[-1] |
||
| 64 | |||
| 65 | text = ' '.join(parts) |
||
| 66 | |||
| 67 | self.text = text |
||
| 68 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.