Showing 77 of 77 total issues
Function createNodeService
has a Cognitive Complexity of 127 (exceeds 20 allowed). Consider refactoring. Open
func createNodeService(registry *ServiceRegistry) *service.Service {
var startedTime time.Time
isAvailable := func(nodeID string) bool {
node, exists := registry.nodes.findNode(nodeID)
return exists && node.IsAvailable()
- 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 mergeConfigs
has a Cognitive Complexity of 90 (exceeds 20 allowed). Consider refactoring. Open
func mergeConfigs(baseConfig moleculer.Config, userConfig []*moleculer.Config) moleculer.Config {
if len(userConfig) > 0 {
for _, config := range userConfig {
if config.Services != nil {
baseConfig.Services = mergeMaps(baseConfig.Services, config.Services)
- 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
File service.go
has 845 lines of code (exceeds 500 allowed). Consider refactoring. Open
package service
import (
"errors"
"fmt"
Function createNodeService
has 249 lines of code (exceeds 50 allowed). Consider refactoring. Open
func createNodeService(registry *ServiceRegistry) *service.Service {
var startedTime time.Time
isAvailable := func(nodeID string) bool {
node, exists := registry.nodes.findNode(nodeID)
return exists && node.IsAvailable()
RawPayload
has 46 methods (exceeds 20 allowed). Consider refactoring. Open
type RawPayload struct {
source interface{}
}
JSONPayload
has 44 methods (exceeds 20 allowed). Consider refactoring. Open
type JSONPayload struct {
result gjson.Result
logger *log.Entry
}
PubSub
has 42 methods (exceeds 20 allowed). Consider refactoring. Open
type PubSub struct {
logger *log.Entry
transport transit.Transport
broker *moleculer.BrokerDelegates
isConnected bool
File pubsub.go
has 646 lines of code (exceeds 500 allowed). Consider refactoring. Open
package pubsub
import (
"errors"
"fmt"
Method TCPTransporter.onGossipRequest
has a Cognitive Complexity of 50 (exceeds 20 allowed). Consider refactoring. Open
func (transporter *TCPTransporter) onGossipRequest(msgBytes *[]byte) {
payload := transporter.serializer.BytesToPayload(msgBytes)
sender := payload.Get("sender").String()
transporter.logger.Trace("Received gossip request from " + sender)
- 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
ServiceRegistry
has 36 methods (exceeds 20 allowed). Consider refactoring. Open
type ServiceRegistry struct {
logger *log.Entry
transit transit.Transit
localNode moleculer.Node
nodes *NodeCatalog
ServiceBroker
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
type ServiceBroker struct {
namespace string
logger *log.Entry
File payload.go
has 574 lines of code (exceeds 500 allowed). Consider refactoring. Open
package payload
import (
"errors"
"fmt"
Similar blocks of code found in 2 locations. Consider refactoring. Open
func (serviceCatalog *ServiceCatalog) updateEvents(serviceMap map[string]interface{}, current *service.Service) ([]map[string]interface{}, []service.Event, []service.Event) {
var updated []map[string]interface{}
var newEvents, deletedEvents []service.Event
events := serviceMap["events"].(map[string]interface{})
- 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 296.
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
func (serviceCatalog *ServiceCatalog) updateActions(serviceMap map[string]interface{}, current *service.Service) ([]map[string]interface{}, []service.Action, []service.Action) {
var updatedActions []map[string]interface{}
var newActions, deletedActions []service.Action
actions := serviceMap["actions"].(map[string]interface{})
- 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 296.
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
File broker.go
has 566 lines of code (exceeds 500 allowed). Consider refactoring. Open
package broker
import (
"errors"
"strings"
File jsonSerializer.go
has 563 lines of code (exceeds 500 allowed). Consider refactoring. Open
package serializer
import (
"bytes"
"encoding/json"
Method TCPTransporter.onGossipRequest
has 107 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (transporter *TCPTransporter) onGossipRequest(msgBytes *[]byte) {
payload := transporter.serializer.BytesToPayload(msgBytes)
sender := payload.Get("sender").String()
transporter.logger.Trace("Received gossip request from " + sender)
Method TCPTransporter.onGossipResponse
has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring. Open
func (transporter *TCPTransporter) onGossipResponse(msgBytes *[]byte) {
payload := transporter.serializer.BytesToPayload(msgBytes)
sender := payload.Get("sender").String()
transporter.logger.Trace("Received gossip response from " + sender)
- 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 mergeConfigs
has 92 lines of code (exceeds 50 allowed). Consider refactoring. Open
func mergeConfigs(baseConfig moleculer.Config, userConfig []*moleculer.Config) moleculer.Config {
if len(userConfig) > 0 {
for _, config := range userConfig {
if config.Services != nil {
baseConfig.Services = mergeMaps(baseConfig.Services, config.Services)
Context
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
type Context struct {
id string
requestID string
broker *moleculer.BrokerDelegates
targetNodeID string