docker/swarmkit

View on GitHub
agent/session.go

Summary

Maintainability
C
7 hrs
Test Coverage

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

func (s *session) watch(ctx context.Context) error {
    logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).watch"})
    logger.Debugf("")
    var (
        resp            *api.AssignmentsMessage
Severity: Minor
Found in agent/session.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 session.watch has 69 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (s *session) watch(ctx context.Context) error {
    logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).watch"})
    logger.Debugf("")
    var (
        resp            *api.AssignmentsMessage
Severity: Minor
Found in agent/session.go - About 1 hr to fix

    Method session.sendTaskStatuses has 6 return statements (exceeds 4 allowed).
    Open

    func (s *session) sendTaskStatuses(ctx context.Context, updates ...*api.UpdateTaskStatusRequest_TaskStatusUpdate) ([]*api.UpdateTaskStatusRequest_TaskStatusUpdate, error) {
        if len(updates) < 1 {
            return nil, nil
        }
    
    
    Severity: Major
    Found in agent/session.go - About 40 mins to fix

      Method session.watch has 6 return statements (exceeds 4 allowed).
      Open

      func (s *session) watch(ctx context.Context) error {
          logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).watch"})
          logger.Debugf("")
          var (
              resp            *api.AssignmentsMessage
      Severity: Major
      Found in agent/session.go - About 40 mins to fix

        Method session.logSubscriptions has 6 return statements (exceeds 4 allowed).
        Open

        func (s *session) logSubscriptions(ctx context.Context) error {
            logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).logSubscriptions"})
            logger.Debugf("")
        
            client := api.NewLogBrokerClient(s.conn.ClientConn)
        Severity: Major
        Found in agent/session.go - About 40 mins to fix

          Function newSession has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func newSession(ctx context.Context, agent *Agent, delay time.Duration, sessionID string, description *api.NodeDescription) *session {
          Severity: Minor
          Found in agent/session.go - About 35 mins to fix

            There are no issues that match your filters.

            Category
            Status