rl404/go-malscraper

View on GitHub
pkg/utils/time.go

Summary

Maintainability
C
1 day
Test Coverage

Function StrToTime has 84 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func StrToTime(str string) (t time.Time, isValid bool) {
    str = strings.TrimSpace(str)
    if str == "" {
        return time.Time{}, false
    }
Severity: Major
Found in pkg/utils/time.go - About 2 hrs to fix

    Function StrToTime has 22 return statements (exceeds 4 allowed).
    Open

    func StrToTime(str string) (t time.Time, isValid bool) {
        str = strings.TrimSpace(str)
        if str == "" {
            return time.Time{}, false
        }
    Severity: Major
    Found in pkg/utils/time.go - About 2 hrs to fix

      Function StrToTime has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
      Open

      func StrToTime(str string) (t time.Time, isValid bool) {
          str = strings.TrimSpace(str)
          if str == "" {
              return time.Time{}, false
          }
      Severity: Minor
      Found in pkg/utils/time.go - 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 StrToDate has 61 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func StrToDate(str string) (y, m, d int) {
          str = strings.TrimSpace(str)
          if str == "" {
              return 0, 0, 0
          }
      Severity: Minor
      Found in pkg/utils/time.go - About 1 hr to fix

        Function StrToDate has 13 return statements (exceeds 4 allowed).
        Open

        func StrToDate(str string) (y, m, d int) {
            str = strings.TrimSpace(str)
            if str == "" {
                return 0, 0, 0
            }
        Severity: Major
        Found in pkg/utils/time.go - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

              if match, _ := regexp.MatchString(`([a-z]+) ([0-9]{1,2})$`, str); match {
                  return 0, months[spltStr[0]], StrToNum(spltStr[1])
              } else
          
              // 2021
          Severity: Major
          Found in pkg/utils/time.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                if match, _ := regexp.MatchString(`Today, ([0-9]{1,2}):([0-9]{2}) (AM|PM)`, str); match {
                    today := now.Format("Jan 2, 2006")
                    str = strings.Replace(str, "Today,", today, -1)
                    return StrToTime(str)
                } else
            Severity: Major
            Found in pkg/utils/time.go - About 45 mins to fix

              Function StrToDate has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
              Open

              func StrToDate(str string) (y, m, d int) {
                  str = strings.TrimSpace(str)
                  if str == "" {
                      return 0, 0, 0
                  }
              Severity: Minor
              Found in pkg/utils/time.go - 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