simonmittag/p0d

View on GitHub
p0d.go

Summary

Maintainability
F
4 days
Test Coverage
C
74%

File p0d.go has 884 lines of code (exceeds 500 allowed). Consider refactoring.
Confirmed

package p0d

import (
    "bytes"
    "context"
Severity: Major
Found in p0d.go - About 1 day to fix

    Method P0d.initLog has 144 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (p *P0d) initLog() {
        PrintLogo()
        PrintVersion()
        fmt.Printf("\n")
        if p.Config.File != "" {
    Severity: Major
    Found in p0d.go - About 4 hrs to fix

      P0d has 24 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type P0d struct {
          ID          string
          Time        Time
          Config      Config
          OS          OS
      Severity: Minor
      Found in p0d.go - About 2 hrs to fix

        Method P0d.doLogLive has 88 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (p *P0d) doLogLive() {
            logLiveLock.Lock()
            elpsd := time.Now()
        
            lw := p.liveWriters
        Severity: Major
        Found in p0d.go - About 2 hrs to fix

          Method P0d.Race has 77 lines of code (exceeds 50 allowed). Consider refactoring.
          Confirmed

          func (p *P0d) Race() {
              osStatsDone := make(chan struct{}, 2)
              p.initOSStats(osStatsDone)
              p.detectRemoteConnSettings()
              p.initLog()
          Severity: Major
          Found in p0d.go - About 2 hrs to fix

            Method P0d.scaffoldHttpReq has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
            Open

            func (p *P0d) scaffoldHttpReq() *http.Request {
                var body io.Reader
            
                //multipartwriter adds a boundary
                var mpContentType string
            Severity: Minor
            Found in p0d.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

            Method P0d.initLog has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
            Open

            func (p *P0d) initLog() {
                PrintLogo()
                PrintVersion()
                fmt.Printf("\n")
                if p.Config.File != "" {
            Severity: Minor
            Found in p0d.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

            Avoid deeply nested control flow statements.
            Open

                        } else if rr.TLS.Version == tls.VersionTLS11 {
                            p.ReqStats.Sample.TLSVersion = "TLS1.1"
                        } else if rr.TLS.Version == tls.VersionTLS12 {
                            p.ReqStats.Sample.TLSVersion = "TLS1.2"
                        } else if rr.TLS.Version == tls.VersionTLS13 {
            Severity: Major
            Found in p0d.go - About 45 mins to fix

              Method P0d.Race has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
              Open

              func (p *P0d) Race() {
                  osStatsDone := make(chan struct{}, 2)
                  p.initOSStats(osStatsDone)
                  p.detectRemoteConnSettings()
                  p.initLog()
              Severity: Minor
              Found in p0d.go - 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

              Avoid deeply nested control flow statements.
              Open

                  } else if p.isTimerPhase(Drained) {
                      connMsg += drained
                  }
              Severity: Major
              Found in p0d.go - About 45 mins to fix

                Function NewP0dWithValues has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func NewP0dWithValues(c int, d int, u string, h string, o string, s bool) *P0d {
                Severity: Minor
                Found in p0d.go - About 45 mins to fix

                  Method P0d.doReqAtmpts has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                  Confirmed

                  func (p *P0d) doReqAtmpts(i int, ras chan<- ReqAtmpt, done <-chan struct{}) {
                  ReqAtmpt:
                      for {
                          select {
                          case <-done:
                  Severity: Minor
                  Found in p0d.go - 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 NewP0d has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  func NewP0d(cfg Config, ulimit int64, outputFile string, durationSecs int, interrupt chan os.Signal) *P0d {
                  Severity: Minor
                  Found in p0d.go - About 35 mins to fix

                    Method P0d.initReqAtmpts has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func (p *P0d) initReqAtmpts(done chan struct{}, ras chan ReqAtmpt) {
                    
                        //don't block because execution continues on to live updates
                        go func() {
                            bd := false
                    Severity: Minor
                    Found in p0d.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

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        fmt.Fprintf(lw[i], timefmt(writeThroughputMsg),
                            Cyan(p.Config.byteCount(int64(p.ReqStats.CurBytesWrittenPSec))),
                            Cyan(perSecondMsg),
                            Cyan(p.Config.byteCount(int64(p.ReqStats.MeanBytesWrittenPSec))),
                            Cyan(perSecondMsg),
                    Severity: Major
                    Found in p0d.go and 1 other location - About 1 hr to fix
                    p0d.go on lines 845..852

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 147.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        fmt.Fprintf(lw[i], timefmt(readthroughputMsg),
                            Cyan(p.Config.byteCount(int64(p.ReqStats.CurBytesReadPSec))),
                            Cyan(perSecondMsg),
                            Cyan(p.Config.byteCount(int64(p.ReqStats.MeanBytesReadPSec))),
                            Cyan(perSecondMsg),
                    Severity: Major
                    Found in p0d.go and 1 other location - About 1 hr to fix
                    p0d.go on lines 855..862

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 147.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status