yoyo-project/yoyo

View on GitHub

Showing 52 of 52 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

                if columns, err = adapter.ListColumns(tableName); err == nil {
                    for _, colName := range columns {
                        if column, err := adapter.GetColumn(tableName, colName); err == nil {
                            column.Name = colName
                            table.Columns = append(table.Columns, column)
Severity: Major
Found in internal/reverse/schema.go and 2 other locations - About 50 mins to fix
internal/reverse/schema.go on lines 34..45
internal/reverse/schema.go on lines 46..57

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 120.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method Column.validate has 8 return statements (exceeds 4 allowed).
Open

func (c *Column) validate() error {
    if err := validateName(c.Name); err != nil {
        return err
    }

Severity: Major
Found in internal/schema/schema_validate.go - About 50 mins to fix

    Function FindPackagePath has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
    Open

    func FindPackagePath(path string) (string, error) {
        gopath := os.Getenv("GOPATH")
        var str, p string
        for p = path; len(p) > 4; p = filepath.Dir(p) {
            str = func(p string) string {
    Severity: Minor
    Found in internal/file/files.go - About 45 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

    Method adapter.GetColumn has 6 return statements (exceeds 4 allowed).
    Open

    func (a *adapter) GetColumn(tableName, colName string) (schema.Column, error) {
        var (
            dt         string
            nullable   string
            key        = new(string)
    Severity: Major
    Found in internal/dbms/mysql/adapter_reverse.go - About 40 mins to fix

      Method Database.validate has 6 return statements (exceeds 4 allowed).
      Open

      func (db *Database) validate() (err error) {
          tNames := make(map[string]bool)
          for _, t := range db.Tables {
              if err = t.validate(); err != nil {
                  return fmt.Errorf("%w for table `%s`", err, t.Name)
      Severity: Major
      Found in internal/schema/schema_validate.go - About 40 mins to fix

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

        func NewEntityRepositoryGenerator(packageName string, adapter Adapter, reposPath string, packagePath Finder, db schema.Database) EntityGenerator {
        Severity: Minor
        Found in internal/repository/generate_repository.go - About 35 mins to fix

          Method CityRepository.Search has 5 return statements (exceeds 4 allowed).
          Open

          func (r *CityRepository) Search(query city.Query) (es Citys, err error) {
              var stmt *sql.Stmt
              // ensure the *sql.Stmt is closed after we're done with it
              defer func() {
                  if stmt != nil && r.tx == nil {
          Severity: Major
          Found in example/mysql/yoyo/repositories/repository_city.go - About 35 mins to fix

            Method NoPkTableRepository.Search has 5 return statements (exceeds 4 allowed).
            Open

            func (r *NoPkTableRepository) Search(query no_pk_table.Query) (es NoPkTables, err error) {
                var stmt *sql.Stmt
                // ensure the *sql.Stmt is closed after we're done with it
                defer func() {
                    if stmt != nil && r.tx == nil {
            Severity: Major
            Found in example/mysql/yoyo/repositories/repository_no_pk_table.go - About 35 mins to fix

              Method Reference.validate has 5 return statements (exceeds 4 allowed).
              Open

              func (r *Reference) validate() error {
                  if err := validateName(r.GoName); err != nil {
                      return err
                  }
                  if r.HasMany == r.HasOne {
              Severity: Major
              Found in internal/schema/schema_validate.go - About 35 mins to fix

                Function FindPackagePath has 5 return statements (exceeds 4 allowed).
                Open

                func FindPackagePath(path string) (string, error) {
                    gopath := os.Getenv("GOPATH")
                    var str, p string
                    for p = path; len(p) > 4; p = filepath.Dir(p) {
                        str = func(p string) string {
                Severity: Major
                Found in internal/file/files.go - About 35 mins to fix

                  Method PersonRepository.Search has 5 return statements (exceeds 4 allowed).
                  Open

                  func (r *PersonRepository) Search(query person.Query) (es Persons, err error) {
                      var stmt *sql.Stmt
                      // ensure the *sql.Stmt is closed after we're done with it
                      defer func() {
                          if stmt != nil && r.tx == nil {
                  Severity: Major
                  Found in example/mysql/yoyo/repositories/repository_person.go - About 35 mins to fix

                    Function NewQueryFileGenerator has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func NewQueryFileGenerator(reposPath string, findPackagePath Finder, db schema.Database) EntityGenerator {
                        return func(t schema.Table, w io.StringWriter) error {
                            var methods, functions, imports []string
                    
                            // We always need fmt
                    Severity: Minor
                    Found in internal/repository/generate_query.go - About 25 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

                    Severity
                    Category
                    Status
                    Source
                    Language