portainer/portainer

View on GitHub
api/http/handler/stacks/stack_delete.go

Summary

Maintainability
D
2 days
Test Coverage

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

func (handler *Handler) stackDeleteKubernetesByName(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
    stackName, err := request.RetrieveRouteVariableValue(r, "name")
    if err != nil {
        return httperror.BadRequest("Invalid stack identifier route variable", err)
    }
Severity: Minor
Found in api/http/handler/stacks/stack_delete.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 Handler.stackDeleteKubernetesByName has 89 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (handler *Handler) stackDeleteKubernetesByName(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
    stackName, err := request.RetrieveRouteVariableValue(r, "name")
    if err != nil {
        return httperror.BadRequest("Invalid stack identifier route variable", err)
    }
Severity: Major
Found in api/http/handler/stacks/stack_delete.go - About 2 hrs to fix

    Method Handler.stackDelete has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
    Open

    func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
        stackID, err := request.RetrieveRouteVariableValue(r, "id")
        if err != nil {
            return httperror.BadRequest("Invalid stack identifier route variable", err)
        }
    Severity: Minor
    Found in api/http/handler/stacks/stack_delete.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 Handler.stackDelete has 85 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
        stackID, err := request.RetrieveRouteVariableValue(r, "id")
        if err != nil {
            return httperror.BadRequest("Invalid stack identifier route variable", err)
        }
    Severity: Major
    Found in api/http/handler/stacks/stack_delete.go - About 2 hrs to fix

      Method Handler.stackDelete has 20 return statements (exceeds 4 allowed).
      Open

      func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
          stackID, err := request.RetrieveRouteVariableValue(r, "id")
          if err != nil {
              return httperror.BadRequest("Invalid stack identifier route variable", err)
          }
      Severity: Major
      Found in api/http/handler/stacks/stack_delete.go - About 1 hr to fix

        Method Handler.deleteStack has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
        Open

        func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.Stack, endpoint *portainer.Endpoint) error {
            if stack.Type == portainer.DockerSwarmStack {
                stack.Name = handler.SwarmStackManager.NormalizeStackName(stack.Name)
        
                if stackutils.IsRelativePathStack(stack) {
        Severity: Minor
        Found in api/http/handler/stacks/stack_delete.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 Handler.stackDeleteKubernetesByName has 15 return statements (exceeds 4 allowed).
        Open

        func (handler *Handler) stackDeleteKubernetesByName(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
            stackName, err := request.RetrieveRouteVariableValue(r, "name")
            if err != nil {
                return httperror.BadRequest("Invalid stack identifier route variable", err)
            }
        Severity: Major
        Found in api/http/handler/stacks/stack_delete.go - About 1 hr to fix

          Method Handler.deleteStack has 10 return statements (exceeds 4 allowed).
          Open

          func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.Stack, endpoint *portainer.Endpoint) error {
              if stack.Type == portainer.DockerSwarmStack {
                  stack.Name = handler.SwarmStackManager.NormalizeStackName(stack.Name)
          
                  if stackutils.IsRelativePathStack(stack) {
          Severity: Major
          Found in api/http/handler/stacks/stack_delete.go - About 1 hr to fix

            Method Handler.deleteExternalStack has 9 return statements (exceeds 4 allowed).
            Open

            func (handler *Handler) deleteExternalStack(r *http.Request, w http.ResponseWriter, stackName string, securityContext *security.RestrictedRequestContext) *httperror.HandlerError {
                endpointID, err := request.RetrieveNumericQueryParameter(r, "endpointId", false)
                if err != nil {
                    return httperror.BadRequest("Invalid query parameter: endpointId", err)
                }
            Severity: Major
            Found in api/http/handler/stacks/stack_delete.go - About 55 mins to fix

              There are no issues that match your filters.

              Category
              Status