boynux/squid-exporter

View on GitHub
collector/client.go

Summary

Maintainability
C
1 day
Test Coverage

Function decodeInfoStrings has a Cognitive Complexity of 40 (exceeds 20 allowed). Consider refactoring.
Open

func decodeInfoStrings(line string) (types.Counter, error) {
    if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
        return types.Counter{}, nil
    }

Severity: Minor
Found in collector/client.go - About 3 hrs 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 decodeInfoStrings has 72 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func decodeInfoStrings(line string) (types.Counter, error) {
    if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
        return types.Counter{}, nil
    }

Severity: Minor
Found in collector/client.go - About 1 hr to fix

    Method CacheObjectClient.GetInfos has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
    Open

    func (c *CacheObjectClient) GetInfos() (types.Counters, error) {
        var infos types.Counters
    
        reader, err := c.readFromSquid("info")
        if err != nil {
    Severity: Minor
    Found in collector/client.go - About 55 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 deeply nested control flow statements.
    Open

                        if slices := strings.Split(value, " "); len(slices) > 0 {
                            value = slices[1]
                        }
    Severity: Major
    Found in collector/client.go - About 45 mins to fix

      Function decodeInfoStrings has 7 return statements (exceeds 4 allowed).
      Open

      func decodeInfoStrings(line string) (types.Counter, error) {
          if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
              return types.Counter{}, nil
          }
      
      
      Severity: Major
      Found in collector/client.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if len(value) > equalTwo {
                                value = strings.Split(strings.TrimSpace(value[equalTwo+1:]), " ")[0]
                            }
        Severity: Major
        Found in collector/client.go - About 45 mins to fix

          Function decodeServiceTimeStrings has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
          Open

          func decodeServiceTimeStrings(line string) (types.Counter, error) {
              if strings.HasSuffix(line, ":\n") { // A header line isn't a metric
                  return types.Counter{}, nil
              }
              if equal := strings.Index(line, ":"); equal >= 0 {
          Severity: Minor
          Found in collector/client.go - 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

          There are no issues that match your filters.

          Category
          Status