File serial.py
has 468 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""Serial communication and card authentication."""
__author__ = "opliko"
__license__ = "MIT"
__version__ = "0.8.b0"
Function extract_uid
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def extract_uid(self, block0: Union[str, bytearray]) -> str:
"""Extract UID from block 0.
Works with all MiFare UID types :)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return uid.hex()
Rename field "serial" Open
self.serial = aioserial.AioSerial(
- Read upRead up
- Exclude checks
It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.
Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.
Noncompliant Code Example
class Foo: foo = '' def getFoo(self): ... foo = Foo() foo.getFoo() # what does this return?
Compliant Solution
class Foo: name = '' def getName(self): ... foo = Foo() foo.getName()
Refactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed. Open
def extract_uid(self, block0: Union[str, bytearray]) -> str:
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.