Showing 37 of 77 total issues
Method EventCatalog.Find
has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring. Open
func (eventCatalog *EventCatalog) Find(name string, groups []string, preferLocal bool, localOnly bool, stg strategy.Strategy) []*EventEntry {
events, exists := eventCatalog.events.Load(name)
if !exists {
return make([]*EventEntry, 0)
}
- 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 ServiceRegistry.RemoteNodeInfoReceived
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
func (registry *ServiceRegistry) RemoteNodeInfoReceived(message moleculer.Payload) {
registry.nodeReceivedMutex.Lock()
defer registry.nodeReceivedMutex.Unlock()
msgMap := message.RawMap()
Method TCPTransporter.onGossipResponse
has 64 lines of code (exceeds 50 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)
Avoid deeply nested control flow statements. Open
if selected := stg.Select(nodes); selected != nil {
entry := (*selected).(*EventEntry)
result = append(result, entry)
}
Method RawPayload.Get
has 7 return statements (exceeds 4 allowed). Open
func (p *RawPayload) Get(s string, defaultValue ...interface{}) moleculer.Payload {
if _, ok := p.mapGet(s); ok {
if defaultValue != nil {
return p.getKey(s, defaultValue...)
}
Avoid deeply nested control flow statements. Open
} else if strings.ToUpper(broker.config.LogLevel) == "FATAL" {
log.SetLevel(log.FatalLevel)
} else {
log.SetLevel(log.InfoLevel)
}
Avoid deeply nested control flow statements. Open
} else if isKafka(pubsub.broker.Config.Transporter) {
pubsub.logger.Info("Transporter: KafkaTransporter")
transport = pubsub.createKafkaTransporter()
} else {
pubsub.logger.Info("Transporter: Memory")
Method TCPTransporter.onGossipResponse
has 7 return statements (exceeds 4 allowed). 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)
Method TCPTransporter.onGossipRequest
has 6 return statements (exceeds 4 allowed). 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.Publish
has 6 return statements (exceeds 4 allowed). Open
func (transporter *TCPTransporter) Publish(command, nodeID string, message moleculer.Payload) {
transporter.logger.Debug("TCPTransporter.Publish() command: " + command + " to nodeID: " + nodeID)
if command == "DISCOVER" {
if transporter.udpServer != nil {
transporter.udpServer.BroadcastDiscoveryMessage()
Method EventCatalog.Find
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
func (eventCatalog *EventCatalog) Find(name string, groups []string, preferLocal bool, localOnly bool, stg strategy.Strategy) []*EventEntry {
Method UdpServer.joinMulticastGroup
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
func (u *UdpServer) joinMulticastGroup(multicast string, udpConn *net.UDPConn, multicastTTL int, ip string, port int) (*ipv4.PacketConn, error) {
Method UdpServer.startServer
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
func (u *UdpServer) startServer(ip string, port int, multicast string, multicastTTL int, discoveryTargets []string) error {
Function cleanUpForSerialization
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func cleanUpForSerialization(values *map[string]interface{}) *map[string]interface{} {
result := map[string]interface{}{}
for key, value := range *values {
vType := payload.GetValueType(&value)
mTransformer := payload.MapTransformer(&value)
- 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 NodeCatalog.GetNodeByAddress
has 5 return statements (exceeds 4 allowed). Open
func (catalog *NodeCatalog) GetNodeByAddress(address string) moleculer.Node {
host, portString, err := net.SplitHostPort(address)
if err != nil {
catalog.logger.Error("GetNodeByAddress() Error parsing address: ", address)
Method AmqpTransporter.subscribeInternal
has 5 return statements (exceeds 4 allowed). Open
func (t *AmqpTransporter) subscribeInternal(subscriber subscriber) {
if t.channel == nil {
return
}
Method AmqpTransporter.Connect
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
func (t *AmqpTransporter) Connect(registry moleculer.Registry) chan error {
endChan := make(chan error)
go func() {
t.logger.Debug("AMQP Connect() - url: ", t.opts.Url)
- 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"