moleculer-go/moleculer

View on GitHub

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)
    }
Severity: Minor
Found in registry/eventCatalog.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 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()
Severity: Minor
Found in registry/registry.go - About 1 hr to fix

    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)
    Severity: Minor
    Found in transit/tcp/gossip.go - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

          } else if strings.ToUpper(broker.config.LogLevel) == "FATAL" {
              log.SetLevel(log.FatalLevel)
          } else {
              log.SetLevel(log.InfoLevel)
          }
      Severity: Major
      Found in broker/broker.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                        if selected := stg.Select(nodes); selected != nil {
                            entry := (*selected).(*EventEntry)
                            result = append(result, entry)
                        }
        Severity: Major
        Found in registry/eventCatalog.go - About 45 mins to fix

          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")
          Severity: Major
          Found in transit/pubsub/pubsub.go - About 45 mins to fix

            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)
            Severity: Major
            Found in transit/tcp/gossip.go - About 45 mins to fix

              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...)
                      }
              Severity: Major
              Found in payload/payload.go - About 45 mins to fix

                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()
                Severity: Major
                Found in transit/tcp/tcp-transporter.go - About 40 mins to fix

                  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)
                  Severity: Major
                  Found in transit/tcp/gossip.go - About 40 mins to fix

                    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 {
                    Severity: Minor
                    Found in registry/eventCatalog.go - About 35 mins to fix

                      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 {
                      Severity: Minor
                      Found in transit/tcp/udp.go - About 35 mins to fix

                        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) {
                        Severity: Minor
                        Found in transit/tcp/udp.go - About 35 mins to fix

                          Method AmqpTransporter.subscribeInternal has 5 return statements (exceeds 4 allowed).
                          Open

                          func (t *AmqpTransporter) subscribeInternal(subscriber subscriber) {
                              if t.channel == nil {
                                  return
                              }
                          
                          
                          Severity: Major
                          Found in transit/amqp/amqp.go - About 35 mins to fix

                            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)
                            Severity: Major
                            Found in registry/nodeCatalog.go - About 35 mins to fix

                              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)
                              Severity: Minor
                              Found in serializer/jsonSerializer.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

                              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)
                              Severity: Minor
                              Found in transit/amqp/amqp.go - About 25 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

                              Severity
                              Category
                              Status
                              Source
                              Language