MiraitSystems/enju_trunk

View on GitHub
lib/enju_trunk/resourceadapter/import_article.rb

Summary

Maintainability
F
3 days
Test Coverage

Method article_attributes has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
Open

    def article_attributes(origin_datas, sheet)
      attrs = {}
      Manifestation.article_output_columns.each do |column|
        name, value = sheet.field_name_and_data(origin_datas, column)

Severity: Minor
Found in lib/enju_trunk/resourceadapter/import_article.rb - About 1 day 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 find_same_item has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def find_same_item(attrs, manifestation_type)
      conditions = ["((manifestations).manifestation_type_id = \'#{manifestation_type.id}\')"] # FIXME!
      attrs.each do |key, value|
        case key
        when 'creators', 'subjects'
Severity: Minor
Found in lib/enju_trunk/resourceadapter/import_article.rb - About 4 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 article_attributes has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def article_attributes(origin_datas, sheet)
      attrs = {}
      Manifestation.article_output_columns.each do |column|
        name, value = sheet.field_name_and_data(origin_datas, column)

Severity: Major
Found in lib/enju_trunk/resourceadapter/import_article.rb - About 2 hrs to fix

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

        def find_same_item(attrs, manifestation_type)
          conditions = ["((manifestations).manifestation_type_id = \'#{manifestation_type.id}\')"] # FIXME!
          attrs.each do |key, value|
            case key
            when 'creators', 'subjects'
    Severity: Minor
    Found in lib/enju_trunk/resourceadapter/import_article.rb - About 1 hr to fix

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

          def create_article_manifestation(attrs, item, manifestation_type, mode = 'edit')
            manifestation = nil
            if item
               manifestation = item.manifestation
            else
      Severity: Minor
      Found in lib/enju_trunk/resourceadapter/import_article.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 create_article_item has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def create_article_item(attrs, manifestation, item, textfile, numbering, mode = 'edit')
            unless item
              if manifestation.items.size < 1
                mode = 'create'
                item = Item.new
      Severity: Minor
      Found in lib/enju_trunk/resourceadapter/import_article.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 process_article_data has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def process_article_data(import_textresult, origin_datas, sheet, textfile, numbering)
            check_article_datas_has_necessary_field(origin_datas, sheet)
      
            attrs = article_attributes(origin_datas, sheet)
            item, mode, error_msg = find_same_item(attrs, sheet.manifestation_type)
      Severity: Minor
      Found in lib/enju_trunk/resourceadapter/import_article.rb - About 1 hr to fix

        Method create_article_item has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def create_article_item(attrs, manifestation, item, textfile, numbering, mode = 'edit')
        Severity: Minor
        Found in lib/enju_trunk/resourceadapter/import_article.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                          start_page = fix_data(page.split('-')[0]) rescue ''
          Severity: Major
          Found in lib/enju_trunk/resourceadapter/import_article.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                            issue_number_string  = value.split('*')[1] rescue ''
            Severity: Major
            Found in lib/enju_trunk/resourceadapter/import_article.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                              volume_number_string = value.split('*')[0] rescue ''
              Severity: Major
              Found in lib/enju_trunk/resourceadapter/import_article.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                end_page   = fix_data(page.split('-')[1]) rescue ''
                Severity: Major
                Found in lib/enju_trunk/resourceadapter/import_article.rb - About 45 mins to fix

                  Method process_article_data has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def process_article_data(import_textresult, origin_datas, sheet, textfile, numbering)
                  Severity: Minor
                  Found in lib/enju_trunk/resourceadapter/import_article.rb - About 35 mins to fix

                    Method process_article_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def process_article_data(import_textresult, origin_datas, sheet, textfile, numbering)
                          check_article_datas_has_necessary_field(origin_datas, sheet)
                    
                          attrs = article_attributes(origin_datas, sheet)
                          item, mode, error_msg = find_same_item(attrs, sheet.manifestation_type)
                    Severity: Minor
                    Found in lib/enju_trunk/resourceadapter/import_article.rb - About 35 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

                            current_user = User.where(:username => 'admin').first
                            import_textresult.item.retain(current_user) if import_textresult.item.available_for_retain?
                            import_textresult.error_msg = I18n.t(
                              'resource_import_file.reserved_item',
                              :username => import_textresult.item.reserve.user.username,
                    Severity: Minor
                    Found in lib/enju_trunk/resourceadapter/import_article.rb and 1 other location - About 35 mins to fix
                    app/models/resource_import_file.rb on lines 165..167

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

                    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