Showing 44 of 44 total issues
Function caduceus
has 150 lines of code (exceeds 50 allowed). Consider refactoring. Open
func caduceus(arguments []string) int {
beginCaduceus := time.Now()
var (
f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
Function authenticationMiddleware
has 148 lines of code (exceeds 50 allowed). Consider refactoring. Open
func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
if registry == nil {
return nil, errors.New("nil registry")
}
Function Metrics
has 120 lines of code (exceeds 50 allowed). Consider refactoring. Open
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: IncomingQueueDepth,
Help: "The depth of the queue behind the incoming handlers.",
Method CaduceusOutboundSender.send
has 87 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (obs *CaduceusOutboundSender) send(urls *ring.Ring, secret, acceptType string, msg *wrp.Message) {
defer func() {
if r := recover(); nil != r {
obs.droppedPanic.Add(1.0)
obs.logger.Error("goroutine send() panicked", zap.String("id", obs.id), zap.Any("panic", r))
File outboundSender.go
has 519 lines of code (exceeds 500 allowed). Consider refactoring. Open
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
Method CaduceusOutboundSender.Update
has 72 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
// Validate the failure URL, if present
if "" != wh.Webhook.FailureURL {
if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
Function authenticationMiddleware
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
if registry == nil {
return nil, errors.New("nil registry")
}
- 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 ServerHandler.ServeHTTP
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
eventType := unknownEventType
// find time difference, add to metric after function finishes
defer func(s time.Time) {
sh.recordQueueLatencyToHistogram(s, eventType)
Function getDoErrReason
has 13 return statements (exceeds 4 allowed). Open
func getDoErrReason(err error) string {
var d *net.DNSError
if err == nil {
return noErrReason
} else if errors.Is(err, context.DeadlineExceeded) {
Method CaduceusOutboundSender.Queue
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (obs *CaduceusOutboundSender) Queue(msg *wrp.Message) {
obs.mutex.RLock()
deliverUntil := obs.deliverUntil
dropUntil := obs.dropUntil
events := obs.events
Method OutboundSenderFactory.New
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) {
if _, err = url.ParseRequestURI(osf.Listener.Webhook.Config.URL); nil != err {
return
}
Function caduceus
has 11 return statements (exceeds 4 allowed). Open
func caduceus(arguments []string) int {
beginCaduceus := time.Now()
var (
f = pflag.NewFlagSet(applicationName, pflag.ContinueOnError)
Function authenticationMiddleware
has 10 return statements (exceeds 4 allowed). Open
func authenticationMiddleware(v *viper.Viper, logger *zap.Logger, registry xmetrics.Registry) (*alice.Chain, error) {
if registry == nil {
return nil, errors.New("nil registry")
}
Function NewPrimaryHandler
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
func NewPrimaryHandler(l *zap.Logger, v *viper.Viper, registry xmetrics.Registry, sw *ServerHandler, webhookSvc ancla.Service, router *mux.Router, prevVersionSupport bool) (*mux.Router, error) {
Avoid deeply nested control flow statements. Open
} else if errors.Is(err, &net.ParseError{}) {
return parseAddrErrReason
} else if errors.Is(err, net.InvalidAddrError("")) {
return invalidAddrReason
} else if errors.As(err, &d) {
Method OutboundSenderFactory.New
has 6 return statements (exceeds 4 allowed). Open
func (osf OutboundSenderFactory) New() (obs OutboundSender, err error) {
if _, err = url.ParseRequestURI(osf.Listener.Webhook.Config.URL); nil != err {
return
}
Method CaduceusOutboundSender.queueOverflow
has 6 return statements (exceeds 4 allowed). Open
func (obs *CaduceusOutboundSender) queueOverflow() {
obs.mutex.Lock()
if time.Now().Before(obs.dropUntil) {
obs.mutex.Unlock()
return
Method ServerHandler.ServeHTTP
has 6 return statements (exceeds 4 allowed). Open
func (sh *ServerHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
eventType := unknownEventType
// find time difference, add to metric after function finishes
defer func(s time.Time) {
sh.recordQueueLatencyToHistogram(s, eventType)
Method CaduceusOutboundSender.Update
has 6 return statements (exceeds 4 allowed). Open
func (obs *CaduceusOutboundSender) Update(wh ancla.InternalWebhook) (err error) {
// Validate the failure URL, if present
if "" != wh.Webhook.FailureURL {
if _, err = url.ParseRequestURI(wh.Webhook.FailureURL); nil != err {
Similar blocks of code found in 2 locations. Consider refactoring. Open
caduceusSenderWrapper := &CaduceusSenderWrapper{
sender: swf.Sender,
numWorkersPerSender: swf.NumWorkersPerSender,
queueSizePerSender: swf.QueueSizePerSender,
deliveryRetries: swf.DeliveryRetries,
- 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 103.
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