lib/midb/server_model.rb

Summary

Maintainability
F
4 days
Test Coverage

File server_model.rb has 345 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'midb/server_controller'
require 'midb/dbengine_model'
require 'midb/server_view'
require 'midb/hooks'

Severity: Minor
Found in lib/midb/server_model.rb - About 4 hrs to fix

Method post has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

      def post(data)
        jss = self.get_structure() # For referencing purposes

        input = self.query_to_hash(data)
        bad_request = false
Severity: Minor
Found in lib/midb/server_model.rb - About 3 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 get_matching_rows has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

      def get_matching_rows(column, pattern)
        jso = Hash.new() 
        jss = self.get_structure()
        db_column = nil
        # Is the column recognized?
Severity: Minor
Found in lib/midb/server_model.rb - About 3 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 post has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def post(data)
        jss = self.get_structure() # For referencing purposes

        input = self.query_to_hash(data)
        bad_request = false
Severity: Major
Found in lib/midb/server_model.rb - About 2 hrs to fix

Method put has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def put(id, data)
        jss = self.get_structure() # For referencing purposes

        input = self.query_to_hash(data)
        bad_request = false
Severity: Major
Found in lib/midb/server_model.rb - About 2 hrs to fix

Method get_entries has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

      def get_entries(id)
        jso = Hash.new()

        dbe = MIDB::API::Dbengine.new(@engine.config, @db)
        dblink = dbe.connect()
Severity: Minor
Found in lib/midb/server_model.rb - 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 get_matching_rows has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def get_matching_rows(column, pattern)
        jso = Hash.new() 
        jss = self.get_structure()
        db_column = nil
        # Is the column recognized?
Severity: Minor
Found in lib/midb/server_model.rb - About 2 hrs to fix

Method put has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def put(id, data)
        jss = self.get_structure() # For referencing purposes

        input = self.query_to_hash(data)
        bad_request = false
Severity: Minor
Found in lib/midb/server_model.rb - 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 delete has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def delete(id)
        # Check if the ID exists
        db = MIDB::API::Dbengine.new(@engine.config, @db)
        dbc = db.connect()
        dbq = db.query(dbc, "SELECT * FROM #{self.get_structure.values[0].split('/')[0]} WHERE id=#{id};")
Severity: Minor
Found in lib/midb/server_model.rb - About 1 hr to fix

Method get_column_entries has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def get_column_entries(column)
        jso = Hash.new() 
        jss = self.get_structure()
        db_column = nil
        # Is the column recognized?
Severity: Minor
Found in lib/midb/server_model.rb - About 1 hr to fix

Method get_all_entries has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def get_all_entries()
        jso = Hash.new()
     
        # Connect to database
        dbe = MIDB::API::Dbengine.new(@engine.config, @db)
Severity: Minor
Found in lib/midb/server_model.rb - 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 delete has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def delete(id)
        # Check if the ID exists
        db = MIDB::API::Dbengine.new(@engine.config, @db)
        dbc = db.connect()
        dbq = db.query(dbc, "SELECT * FROM #{self.get_structure.values[0].split('/')[0]} WHERE id=#{id};")
Severity: Minor
Found in lib/midb/server_model.rb - 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 get_entries has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def get_entries(id)
        jso = Hash.new()

        dbe = MIDB::API::Dbengine.new(@engine.config, @db)
        dblink = dbe.connect()
Severity: Minor
Found in lib/midb/server_model.rb - About 1 hr to fix

Method get_column_entries has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def get_column_entries(column)
        jso = Hash.new() 
        jss = self.get_structure()
        db_column = nil
        # Is the column recognized?
Severity: Minor
Found in lib/midb/server_model.rb - 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 get_all_entries has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def get_all_entries()
        jso = Hash.new()
     
        # Connect to database
        dbe = MIDB::API::Dbengine.new(@engine.config, @db)
Severity: Minor
Found in lib/midb/server_model.rb - About 1 hr to fix

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        rows.each do |row|
          jso[row["id"]] = self.get_structure
          self.get_structure.each do |name, dbi|
            table = dbi.split("/")[0]
            field = dbi.split("/")[1]
Severity: Major
Found in lib/midb/server_model.rb and 1 other location - About 4 hrs to fix
lib/midb/server_model.rb on lines 254..272

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 137.

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

Identical blocks of code found in 2 locations. Consider refactoring.
Open

          rows.each do |row|
            jso[row["id"]] = self.get_structure
            self.get_structure.each do |name, dbi|
              table = dbi.split("/")[0]
              field = dbi.split("/")[1]
Severity: Major
Found in lib/midb/server_model.rb and 1 other location - About 4 hrs to fix
lib/midb/server_model.rb on lines 296..314

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 137.

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

There are no issues that match your filters.

Category
Status