krateng/maloja

View on GitHub
maloja/malojatime.py

Summary

Maintainability
D
1 day
Test Coverage

File malojatime.py has 392 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from datetime import timezone, timedelta, date, time, datetime
from calendar import monthrange
import math
from abc import ABC, abstractmethod

Severity: Minor
Found in maloja/malojatime.py - About 5 hrs to fix

    Function time_pad has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def time_pad(f,t,full=False):
    
        if f is None or t is None: return f,t
    
        # week handling
    Severity: Minor
    Found in maloja/malojatime.py - About 1 hr to fix

    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

    Function time_fix has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def time_fix(t):
        if t is None or isinstance(t,MTRangeGeneric): return t
    
        if isinstance(t, str):
            t = t.lower()
    Severity: Minor
    Found in maloja/malojatime.py - About 1 hr to fix

    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

    Function ranges has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def ranges(since=None,to=None,within=None,timerange=None,step="month",stepn=1,trail=1,max_=None):
    Severity: Major
    Found in maloja/malojatime.py - About 1 hr to fix

      Function next has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def next(self,step=1):
              if abs(step) == math.inf: return None
              if self.precision == 1:
                  return MTRangeGregorian(self.year + step)
              elif self.precision == 2:
      Severity: Minor
      Found in maloja/malojatime.py - About 45 mins to fix

      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

      Function informal_desc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def informal_desc(self):
              # TODO: ignore year when same year etc
              now = datetime.now(tz=timezone.utc)
              today = date(now.year,now.month,now.day)
              if self.precision == 3:
      Severity: Minor
      Found in maloja/malojatime.py - About 45 mins to fix

      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

      Function contextual_desc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def contextual_desc(self,other):
              # TODO: more elegant maybe?
              if not isinstance(other, MTRangeGregorian): return self.desc()
      
              relevant = self.desc().split(" ")
      Severity: Minor
      Found in maloja/malojatime.py - About 35 mins to fix

      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

      Function desc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def desc(self,prefix=False):
              if self.since is not None and self.to is not None:
                  if prefix:
                      return f"from {self.since.contextual_desc(self.to)} to {self.to.desc()}"
                  else:
      Severity: Minor
      Found in maloja/malojatime.py - About 35 mins to fix

      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 ""
      Severity: Major
      Found in maloja/malojatime.py - About 30 mins to fix

        Function ranges has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def ranges(since=None,to=None,within=None,timerange=None,step="month",stepn=1,trail=1,max_=None):
        
            (firstincluded,lastincluded) = time_stamps(since=since,to=to,within=within,range=timerange)
        
            d_start = from_timestamp(firstincluded,step)
        Severity: Minor
        Found in maloja/malojatime.py - About 25 mins to fix

        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

        There are no issues that match your filters.

        Category
        Status