File p0d.go
has 884 lines of code (exceeds 500 allowed). Consider refactoring. Confirmed
package p0d
import (
"bytes"
"context"
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 != "" {
P0d
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
type P0d struct {
ID string
Time Time
Config Config
OS OS
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
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()
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
- 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
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 != "" {
- 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 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 {
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()
- 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 deeply nested control flow statements. Open
} else if p.isTimerPhase(Drained) {
connMsg += drained
}
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 {
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:
- 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
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 {
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
- 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
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),
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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),
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76