ory-am/hydra

View on GitHub
cmd/cli/handler_migrate.go

Summary

Maintainability
C
7 hrs
Test Coverage

Function readMigrations has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
Open

func readMigrations(migrationSourceFS fs.FS, expectedDialects []string) (map[string]*migrationGroup, error) {
    mgs := make(map[string]*migrationGroup)
    err := fs.WalkDir(migrationSourceFS, ".", func(p string, d fs.DirEntry, err2 error) error {
        if err2 != nil {
            fmt.Println("Warning: unexpected error " + err2.Error())
Severity: Minor
Found in cmd/cli/handler_migrate.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

Function readMigrations has 61 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func readMigrations(migrationSourceFS fs.FS, expectedDialects []string) (map[string]*migrationGroup, error) {
    mgs := make(map[string]*migrationGroup)
    err := fs.WalkDir(migrationSourceFS, ".", func(p string, d fs.DirEntry, err2 error) error {
        if err2 != nil {
            fmt.Println("Warning: unexpected error " + err2.Error())
Severity: Minor
Found in cmd/cli/handler_migrate.go - About 1 hr to fix

    Function readMigrations has 11 return statements (exceeds 4 allowed).
    Open

    func readMigrations(migrationSourceFS fs.FS, expectedDialects []string) (map[string]*migrationGroup, error) {
        mgs := make(map[string]*migrationGroup)
        err := fs.WalkDir(migrationSourceFS, ".", func(p string, d fs.DirEntry, err2 error) error {
            if err2 != nil {
                fmt.Println("Warning: unexpected error " + err2.Error())
    Severity: Major
    Found in cmd/cli/handler_migrate.go - About 1 hr to fix

      Method MigrateHandler.MigrateSQL has 8 return statements (exceeds 4 allowed).
      Open

      func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) (err error) {
          p, err := h.makePersister(cmd, args)
          if err != nil {
              return err
          }
      Severity: Major
      Found in cmd/cli/handler_migrate.go - About 50 mins to fix

        Method MigrateHandler.MigrateStatus has 6 return statements (exceeds 4 allowed).
        Open

        func (h *MigrateHandler) MigrateStatus(cmd *cobra.Command, args []string) error {
            p, err := h.makePersister(cmd, args)
            if err != nil {
                return err
            }
        Severity: Major
        Found in cmd/cli/handler_migrate.go - About 40 mins to fix

          Method MigrateHandler.makePersister has 5 return statements (exceeds 4 allowed).
          Open

          func (h *MigrateHandler) makePersister(cmd *cobra.Command, args []string) (p persistence.Persister, err error) {
              var d driver.Registry
          
              if flagx.MustGetBool(cmd, "read-from-env") {
                  d, err = driver.New(
          Severity: Major
          Found in cmd/cli/handler_migrate.go - About 35 mins to fix

            Method migrationGroup.generateSQL has 5 return statements (exceeds 4 allowed).
            Open

            func (mg migrationGroup) generateSQL(sourceFS fs.FS, target string) error {
                ms := mg.Children
                if mg.fallbackDownMigration != nil {
                    ms = append(ms, mg.fallbackDownMigration)
                }
            Severity: Major
            Found in cmd/cli/handler_migrate.go - About 35 mins to fix

              There are no issues that match your filters.

              Category
              Status