metanorma/gb-agencies

View on GitHub
lib/gb_agencies/gb_agencies.rb

Summary

Maintainability
F
4 days
Test Coverage

File gb_agencies.rb has 344 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module GbAgencies
  class Agencies
    def initialize(lang, labels = nil, issuer = nil)
      @lang = lang
      @labels = labels || { "PRC" => "", "industry_standard" => "",
Severity: Minor
Found in lib/gb_agencies/gb_agencies.rb - About 4 hrs to fix

    Method docidentifier has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def docidentifier(scope, prefix, mandate, docyear, docnum)
          initslash = %r{^/}.match(docnum)
          dn = case scope
               when nil
                 docnum
    Severity: Minor
    Found in lib/gb_agencies/gb_agencies.rb - About 55 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 docidentifier has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def docidentifier(scope, prefix, mandate, docyear, docnum)
    Severity: Minor
    Found in lib/gb_agencies/gb_agencies.rb - About 35 mins to fix

      Method standard_agency1 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def standard_agency1(scope, prefix, mandate)
            case scope
            when "national"
              ret = NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
                                  :admin) || nil
      Severity: Minor
      Found in lib/gb_agencies/gb_agencies.rb - 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

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

          SECTOR = { "zh" => {
            AQ: { industry: "安全生产", admin: "国家安全生产管理局" },
            BB: { industry: "包装", admin: "国家发改委" },
            CB: { industry: "船舶", admin: "国防科学工业委员会" },
            CH: { industry: "测绘", admin: "国家测绘局" },
      Severity: Major
      Found in lib/gb_agencies/gb_agencies.rb and 1 other location - About 1 day to fix
      lib/gb_agencies/gb_agencies.rb on lines 77..141

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

      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

          "en" => {
            AQ: { industry: "Production Safety", admin: "State Administration of Work Safety" },
            BB: { industry: "Packaging", admin: "China National Packaging Industry Corporation" },
            CB: { industry: "Ships", admin: "National Defense Commission" },
            CH: { industry: "Surveying and Mapping", admin: "National Bureau of Surveying and Mapping" },
      Severity: Major
      Found in lib/gb_agencies/gb_agencies.rb and 1 other location - About 1 day to fix
      lib/gb_agencies/gb_agencies.rb on lines 11..75

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

      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

            "en" => {
              "11": "Beijing City",
              "12": "Tianjin",
              "13": "Hebei Province",
              "14": "Shanxi Province",
      Severity: Major
      Found in lib/gb_agencies/gb_agencies.rb and 1 other location - About 1 hr to fix
      lib/gb_agencies/gb_agencies.rb on lines 179..213

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

      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

            "zh" => {
              "11": "北京市",
              "12": "天津市",
              "13": "河北省",
              "14": "山西省",
      Severity: Major
      Found in lib/gb_agencies/gb_agencies.rb and 1 other location - About 1 hr to fix
      lib/gb_agencies/gb_agencies.rb on lines 215..249

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

      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