portainer/portainer

View on GitHub
api/datastore/services.go

Summary

Maintainability
F
4 days
Test Coverage

Method Store.Export has a Cognitive Complexity of 98 (exceeds 20 allowed). Consider refactoring.
Open

func (store *Store) Export(filename string) (err error) {

    backup := storeExport{}

    if c, err := store.CustomTemplate().ReadAll(); err != nil {
Severity: Minor
Found in api/datastore/services.go - About 1 day 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 Store.Export has 178 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (store *Store) Export(filename string) (err error) {

    backup := storeExport{}

    if c, err := store.CustomTemplate().ReadAll(); err != nil {
Severity: Major
Found in api/datastore/services.go - About 6 hrs to fix

    Method Store.initServices has 142 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (store *Store) initServices() error {
        authorizationsetService, err := role.NewService(store.connection)
        if err != nil {
            return err
        }
    Severity: Major
    Found in api/datastore/services.go - About 4 hrs to fix

      File services.go has 568 lines of code (exceeds 500 allowed). Consider refactoring.
      Open

      package datastore
      
      import (
          "fmt"
          "os"
      Severity: Minor
      Found in api/datastore/services.go - About 3 hrs to fix

        Store has 28 methods (exceeds 20 allowed). Consider refactoring.
        Open

        type Store struct {
            connection portainer.Connection
        
            fileService               portainer.FileService
            CustomTemplateService     *customtemplate.Service
        Severity: Minor
        Found in api/datastore/services.go - About 3 hrs to fix

          Method Store.initServices has 29 return statements (exceeds 4 allowed).
          Open

          func (store *Store) initServices() error {
              authorizationsetService, err := role.NewService(store.connection)
              if err != nil {
                  return err
              }
          Severity: Major
          Found in api/datastore/services.go - About 2 hrs to fix

            Method Store.Import has 70 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (store *Store) Import(filename string) (err error) {
                backup := storeExport{}
            
                s, err := os.ReadFile(filename)
                if err != nil {
            Severity: Minor
            Found in api/datastore/services.go - About 1 hr to fix

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

              func (store *Store) initServices() error {
                  authorizationsetService, err := role.NewService(store.connection)
                  if err != nil {
                      return err
                  }
              Severity: Minor
              Found in api/datastore/services.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 Store.Import has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
              Open

              func (store *Store) Import(filename string) (err error) {
                  backup := storeExport{}
              
                  s, err := os.ReadFile(filename)
                  if err != nil {
              Severity: Minor
              Found in api/datastore/services.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