dotcloud/docker

View on GitHub
daemon/cluster/swarm.go

Summary

Maintainability
D
2 days
Test Coverage

Method Cluster.Init has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
Open

func (c *Cluster) Init(req types.InitRequest) (string, error) {
    c.controlMutex.Lock()
    defer c.controlMutex.Unlock()
    if c.nr != nil {
        if req.ForceNewCluster {
Severity: Minor
Found in daemon/cluster/swarm.go - About 2 hrs 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 Cluster.Init has 96 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (c *Cluster) Init(req types.InitRequest) (string, error) {
    c.controlMutex.Lock()
    defer c.controlMutex.Unlock()
    if c.nr != nil {
        if req.ForceNewCluster {
Severity: Major
Found in daemon/cluster/swarm.go - About 2 hrs to fix

    File swarm.go has 511 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package cluster // import "github.com/docker/docker/daemon/cluster"
    
    import (
        "context"
        "fmt"
    Severity: Minor
    Found in daemon/cluster/swarm.go - About 2 hrs to fix

      Method Cluster.Leave has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
      Open

      func (c *Cluster) Leave(ctx context.Context, force bool) error {
          c.controlMutex.Lock()
          defer c.controlMutex.Unlock()
      
          c.mu.Lock()
      Severity: Minor
      Found in daemon/cluster/swarm.go - About 2 hrs 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 Cluster.Init has 16 return statements (exceeds 4 allowed).
      Open

      func (c *Cluster) Init(req types.InitRequest) (string, error) {
          c.controlMutex.Lock()
          defer c.controlMutex.Unlock()
          if c.nr != nil {
              if req.ForceNewCluster {
      Severity: Major
      Found in daemon/cluster/swarm.go - About 1 hr to fix

        Function initClusterSpec has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
        Open

        func initClusterSpec(node *swarmnode.Node, spec types.Spec) error {
            ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
            defer cancel()
            for conn := range node.ListenControlSocket(ctx) {
                if ctx.Err() != nil {
        Severity: Minor
        Found in daemon/cluster/swarm.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 Cluster.Join has 57 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (c *Cluster) Join(req types.JoinRequest) error {
            c.controlMutex.Lock()
            defer c.controlMutex.Unlock()
            c.mu.Lock()
            if c.nr != nil {
        Severity: Minor
        Found in daemon/cluster/swarm.go - About 1 hr to fix

          Method Cluster.Leave has 56 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (c *Cluster) Leave(ctx context.Context, force bool) error {
              c.controlMutex.Lock()
              defer c.controlMutex.Unlock()
          
              c.mu.Lock()
          Severity: Minor
          Found in daemon/cluster/swarm.go - About 1 hr to fix

            Method Cluster.Info has 51 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (c *Cluster) Info(ctx context.Context) types.Info {
                info := types.Info{
                    NodeAddr: c.GetAdvertiseAddress(),
                }
                c.mu.RLock()
            Severity: Minor
            Found in daemon/cluster/swarm.go - About 1 hr to fix

              Method Cluster.Leave has 8 return statements (exceeds 4 allowed).
              Open

              func (c *Cluster) Leave(ctx context.Context, force bool) error {
                  c.controlMutex.Lock()
                  defer c.controlMutex.Unlock()
              
                  c.mu.Lock()
              Severity: Major
              Found in daemon/cluster/swarm.go - About 50 mins to fix

                Method Cluster.Join has 8 return statements (exceeds 4 allowed).
                Open

                func (c *Cluster) Join(req types.JoinRequest) error {
                    c.controlMutex.Lock()
                    defer c.controlMutex.Unlock()
                    c.mu.Lock()
                    if c.nr != nil {
                Severity: Major
                Found in daemon/cluster/swarm.go - About 50 mins to fix

                  Method Cluster.UnlockSwarm has 8 return statements (exceeds 4 allowed).
                  Open

                  func (c *Cluster) UnlockSwarm(req types.UnlockRequest) error {
                      c.controlMutex.Lock()
                      defer c.controlMutex.Unlock()
                  
                      c.mu.RLock()
                  Severity: Major
                  Found in daemon/cluster/swarm.go - About 50 mins to fix

                    Function initClusterSpec has 7 return statements (exceeds 4 allowed).
                    Open

                    func initClusterSpec(node *swarmnode.Node, spec types.Spec) error {
                        ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
                        defer cancel()
                        for conn := range node.ListenControlSocket(ctx) {
                            if ctx.Err() != nil {
                    Severity: Major
                    Found in daemon/cluster/swarm.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if isLastManager(reachable, unreachable) {
                                              msg += "Removing the last manager erases all current state of the swarm. Use `--force` to ignore this message. "
                                              return errors.WithStack(notAvailableError(msg))
                                          }
                      Severity: Major
                      Found in daemon/cluster/swarm.go - About 45 mins to fix

                        Method Cluster.GetUnlockKey has 5 return statements (exceeds 4 allowed).
                        Open

                        func (c *Cluster) GetUnlockKey() (string, error) {
                            var resp *swarmapi.GetUnlockKeyResponse
                            if err := c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
                                client := swarmapi.NewCAClient(state.grpcConn)
                        
                        
                        Severity: Major
                        Found in daemon/cluster/swarm.go - About 35 mins to fix

                          Method Cluster.Info has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                          Open

                          func (c *Cluster) Info(ctx context.Context) types.Info {
                              info := types.Info{
                                  NodeAddr: c.GetAdvertiseAddress(),
                              }
                              c.mu.RLock()
                          Severity: Minor
                          Found in daemon/cluster/swarm.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

                          There are no issues that match your filters.

                          Category
                          Status