GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Failed Conditions
Branch 16-refactor-needed (129250)
by Yngve
02:00
created

paytext.paytext.PaymentText.clean()   C

Complexity

Conditions 10

Size

Total Lines 52
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 52
rs 5.9999
c 0
b 0
f 0
cc 10
nop 1

How to fix   Long Method    Complexity   

Long Method

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:

Complexity

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
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
from pprint import pprint
0 ignored issues
show
Unused Code introduced by
Unused pprint imported from pprint
Loading history...
4
from re import sub, compile
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in compile.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Unused Code introduced by
Unused sub imported from re
Loading history...
5
from typing import List, Any
6
7
import iso4217parse
0 ignored issues
show
introduced by
Unable to import 'iso4217parse'
Loading history...
8
9
10
class PaymentText:
1 ignored issue
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
11
    text: str = ''
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
12
13
    def __init__(self, text: str) -> None:
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
14
        self.text = text
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
15
16
    def __repr__(self) -> str:
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
17
        return self.text
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
18
19
    def clean(self) -> None:
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
20
        parts: List[str] = self.text.split()
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
21
22
        # pprint(parts)
23
24
        pattern = compile('\*\d{4}')
1 ignored issue
show
Bug introduced by
A suspicious escape sequence \* was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \d was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
25
26
        try:
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
27
            if pattern.match(parts[0]):
2 ignored issues
show
Comprehensibility Best Practice introduced by
The variable parts does not seem to be defined.
Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
28
                del parts[0]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
29
        except IndexError:
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
30
            return
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
31
32
        pattern = compile('\d{2}\.\d{2}')
1 ignored issue
show
Bug introduced by
A suspicious escape sequence \d was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \. was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
33
34
        if pattern.match(parts[0]):
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
35
            del parts[0]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
36
37
        currency: Any = iso4217parse.by_alpha3(parts[0])
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
38
39
        if isinstance(currency, iso4217parse.Currency):
2 ignored issues
show
Comprehensibility Best Practice introduced by
The variable currency does not seem to be defined.
Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
40
            del parts[0]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
41
            del parts[0]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
42
43
        pattern = compile('\d{1}\.\d{4}')
1 ignored issue
show
Bug introduced by
A suspicious escape sequence \d was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \. was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
44
45
        if pattern.match(parts[-1]):
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
46
            del parts[-1]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
47
            del parts[-1]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
48
49
        pattern = compile('\d{2}\.\d{2}\.\d{2}')
1 ignored issue
show
Bug introduced by
A suspicious escape sequence \d was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \. was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
50
51
        if pattern.match(parts[-1]):
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
52
            del parts[-1]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
53
54
            pattern = compile('.+:')
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
55
56
            if pattern.match(parts[-1]):
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
57
                del parts[-1]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
58
59
        pattern = compile('\d+,\d{2}')
1 ignored issue
show
Bug introduced by
A suspicious escape sequence \d was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
60
61
        if pattern.match(parts[-1]):
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
62
            del parts[-1]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
63
64
            currency: Any = iso4217parse.by_alpha3(parts[-1])
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
65
            if isinstance(currency, iso4217parse.Currency):
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
66
                del parts[-1]
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
67
68
        text = ' '.join(parts)
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
69
70
        self.text = text
1 ignored issue
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
71