bdurand/us_geo

View on GitHub

Showing 63 of 68 total issues

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

  class UrbanAreaCountySubdivision < BaseRecord
    include Area

    belongs_to :county_subdivision, foreign_key: :county_subdivision_geoid, inverse_of: :urban_area_county_subdivisions
    belongs_to :urban_area, foreign_key: :urban_area_geoid, inverse_of: :urban_area_county_subdivisions
Severity: Major
Found in lib/us_geo/urban_area_county_subdivision.rb and 4 other locations - About 3 hrs to fix
lib/us_geo/urban_area_county.rb on lines 5..48
lib/us_geo/zcta_county.rb on lines 5..48
lib/us_geo/zcta_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_urban_area.rb on lines 5..48

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

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

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

  class ZctaUrbanArea < BaseRecord
    include Area

    belongs_to :zcta, foreign_key: :zipcode, inverse_of: :zcta_urban_areas
    belongs_to :urban_area, foreign_key: :urban_area_geoid, inverse_of: :zcta_urban_areas
Severity: Major
Found in lib/us_geo/zcta_urban_area.rb and 4 other locations - About 3 hrs to fix
lib/us_geo/urban_area_county.rb on lines 5..48
lib/us_geo/urban_area_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_county.rb on lines 5..48
lib/us_geo/zcta_county_subdivision.rb on lines 5..48

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

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

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

  class UrbanAreaCounty < BaseRecord
    include Area

    belongs_to :county, foreign_key: :county_geoid, inverse_of: :urban_area_counties
    belongs_to :urban_area, foreign_key: :urban_area_geoid, inverse_of: :urban_area_counties
Severity: Major
Found in lib/us_geo/urban_area_county.rb and 4 other locations - About 3 hrs to fix
lib/us_geo/urban_area_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_county.rb on lines 5..48
lib/us_geo/zcta_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_urban_area.rb on lines 5..48

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

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

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

  class ZctaCountySubdivision < BaseRecord
    include Area

    belongs_to :zcta, foreign_key: :zipcode, inverse_of: :zcta_county_subdivisions
    belongs_to :county_subdivision, foreign_key: :county_subdivision_geoid, inverse_of: :zcta_county_subdivisions
Severity: Major
Found in lib/us_geo/zcta_county_subdivision.rb and 4 other locations - About 3 hrs to fix
lib/us_geo/urban_area_county.rb on lines 5..48
lib/us_geo/urban_area_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_county.rb on lines 5..48
lib/us_geo/zcta_urban_area.rb on lines 5..48

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

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

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

  class ZctaCounty < BaseRecord
    include Area

    belongs_to :zcta, foreign_key: :zipcode, inverse_of: :zcta_counties
    belongs_to :county, foreign_key: :county_geoid, inverse_of: :zcta_counties
Severity: Major
Found in lib/us_geo/zcta_county.rb and 4 other locations - About 3 hrs to fix
lib/us_geo/urban_area_county.rb on lines 5..48
lib/us_geo/urban_area_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_county_subdivision.rb on lines 5..48
lib/us_geo/zcta_urban_area.rb on lines 5..48

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

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 core_based_statistical_area_data has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def core_based_statistical_area_data
      unless defined?(@core_based_statistical_area_data)
        core_based_statistical_areas = {}
        foreach(data_file(USGeoData::CBSA_DELINEATION_FILE), col_sep: ",") do |row|
          cbsa_code = row["CBSA Code"]
Severity: Minor
Found in data/lib/us_geo_data/core_based_statistical_area.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

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

    def add_urban_areas(places)
      overlaps = {}
      foreach(data_file(USGeoData::PLACE_URBAN_AREA_REL_FILE), col_sep: "|") do |row|
        urban_area_geoid = row["GEOID_UA_20"]
        place_geoid = row["GEOID_PLACE_20"]
Severity: Major
Found in data/lib/us_geo_data/place.rb and 1 other location - About 2 hrs to fix
data/lib/us_geo_data/zcta.rb on lines 204..225

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

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

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

    def add_urban_areas(zctas)
      overlaps = {}
      foreach(data_file(USGeoData::ZCTA_URBAN_AREA_REL_FILE), col_sep: "|") do |row|
        urban_area_geoid = row["GEOID_UA_20"]
        zcta5 = row["GEOID_ZCTA5_20"]
Severity: Major
Found in data/lib/us_geo_data/zcta.rb and 1 other location - About 2 hrs to fix
data/lib/us_geo_data/place.rb on lines 202..223

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

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 breadcrumb_links has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  def breadcrumb_links(active = nil)
    return {} if @breadcrumbs.blank?

    objects = @breadcrumbs.values
    region = objects.detect { |b| b.is_a?(USGeo::Region) }
Severity: Minor
Found in explorer_app/app/helpers/application_helper.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 foreach has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def foreach(csv_file, options = {}, &block)
      options = {headers: true}.merge(options)
      encoding = options.delete(:encoding) || "UTF-8"
      file = (csv_file.is_a?(String) ? File.open(csv_file, encoding: encoding) : csv_file)
      begin
Severity: Minor
Found in data/lib/us_geo_data/processor.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 metropolitan_division_data has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def metropolitan_division_data
      unless defined?(@metropolitan_division_data)
        metropolitan_divisions = {}

        foreach(data_file(USGeoData::CBSA_DELINEATION_FILE), col_sep: ",") do |row|
Severity: Minor
Found in data/lib/us_geo_data/metropolitan_division.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

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

    def add_counties(data)
      foreach(data_file(USGeoData::ZCTA_COUNTY_REL_FILE), col_sep: "|") do |row|
        zcta5 = row["GEOID_ZCTA5_20"]
        county_geoid = row["GEOID_COUNTY_20"]
        overlap_land_area = row["AREALAND_PART"].to_f * SQUARE_METERS_TO_MILES
Severity: Major
Found in data/lib/us_geo_data/zcta.rb and 1 other location - About 1 hr to fix
data/lib/us_geo_data/zcta.rb on lines 168..181

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

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

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

    def add_county_subdivisions(data)
      foreach(data_file(USGeoData::ZCTA_COUNTY_SUBDIVISION_REL_FILE), col_sep: "|") do |row|
        zcta5 = row["GEOID_ZCTA5_20"]
        county_subdivision_geoid = row["GEOID_COUSUB_20"]
        overlap_land_area = row["AREALAND_PART"].to_f * SQUARE_METERS_TO_MILES
Severity: Major
Found in data/lib/us_geo_data/zcta.rb and 1 other location - About 1 hr to fix
data/lib/us_geo_data/zcta.rb on lines 151..164

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

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 dump_all has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def dump_all(files = nil)
      files = Array(files)
      counties = County.new
      states = State.new(counties: counties)

Severity: Minor
Found in data/lib/us_geo_data.rb - About 1 hr to fix

    Method preprocess has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def preprocess
          counties_file = File.open(processed_file(COUNTIES_FILE), "w")
          subdivisions_file = File.open(processed_file(SUBDIVISIONS_FILE), "w")
          places_file = File.open(processed_file(PLACES_FILE), "w")
          place_counties_file = File.open(processed_file(PLACE_COUNTIES_FILE), "w")
    Severity: Minor
    Found in data/lib/us_geo_data/gnis.rb - About 1 hr to fix

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

          def dump_all(files = nil)
            files = Array(files)
            counties = County.new
            states = State.new(counties: counties)
      
      
      Severity: Minor
      Found in data/lib/us_geo_data.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 preprocess has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def preprocess
            counties_file = File.open(processed_file(COUNTIES_FILE), "w")
            subdivisions_file = File.open(processed_file(SUBDIVISIONS_FILE), "w")
            places_file = File.open(processed_file(PLACES_FILE), "w")
            place_counties_file = File.open(processed_file(PLACE_COUNTIES_FILE), "w")
      Severity: Minor
      Found in data/lib/us_geo_data/gnis.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 breadcrumb_links has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def breadcrumb_links(active = nil)
          return {} if @breadcrumbs.blank?
      
          objects = @breadcrumbs.values
          region = objects.detect { |b| b.is_a?(USGeo::Region) }
      Severity: Minor
      Found in explorer_app/app/helpers/application_helper.rb - About 1 hr to fix

        Method core_based_statistical_area_data has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def core_based_statistical_area_data
              unless defined?(@core_based_statistical_area_data)
                core_based_statistical_areas = {}
                foreach(data_file(USGeoData::CBSA_DELINEATION_FILE), col_sep: ",") do |row|
                  cbsa_code = row["CBSA Code"]
        Severity: Minor
        Found in data/lib/us_geo_data/core_based_statistical_area.rb - About 1 hr to fix

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

              def dump_csv(output)
                csv = CSV.new(output)
                csv << ["GEOID", "Name", "Short Name", "CSA", "Population", "Housing Units", "Land Area", "Water Area", "Latitude", "Longitude"]
                core_based_statistical_area_data.each_value do |data|
                  csv << [
          Severity: Major
          Found in data/lib/us_geo_data/core_based_statistical_area.rb and 1 other location - About 1 hr to fix
          data/lib/us_geo_data/urban_area.rb on lines 11..28

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

          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

          Severity
          Category
          Status
          Source
          Language