MiraitSystems/enju_trunk

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

Summary

Maintainability
D
2 days
Test Coverage

File resource_import.rb has 408 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'roo'
require File.join(File.expand_path(File.dirname(__FILE__)), 'import_book')
require File.join(File.expand_path(File.dirname(__FILE__)), 'import_article')
class ResourceImport < EnjuTrunk::ResourceAdapter::Base
  include EnjuTrunk::ImportBook
Severity: Minor
Found in lib/enju_trunk/resourceadapter/resource_import.rb - About 5 hrs to fix

    Method field_index_set has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def field_index_set(field_keys)
          names = {}
          field_keys.each do |fk|
            next unless @column_spec[fk] == :plural
            name = field_name(fk)
    Severity: Minor
    Found in lib/enju_trunk/resourceadapter/resource_import.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 import has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

      def import(resource_import_textfile)
        I18n.locale = :ja
    
        adapter = EnjuTrunk::ResourceAdapter::Base.find_by_classname(resource_import_textfile.adapter_name)
        adapter.logger = logger
    Severity: Minor
    Found in lib/enju_trunk/resourceadapter/resource_import.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 import has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def import(resource_import_textfile)
        I18n.locale = :ja
    
        adapter = EnjuTrunk::ResourceAdapter::Base.find_by_classname(resource_import_textfile.adapter_name)
        adapter.logger = logger
    Severity: Major
    Found in lib/enju_trunk/resourceadapter/resource_import.rb - About 2 hrs to fix

      Class Sheet has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Sheet
          def self.new_from_rows(rows)
            new do |obj|
              obj.rows = rows
            end
      Severity: Minor
      Found in lib/enju_trunk/resourceadapter/resource_import.rb - About 2 hrs to fix

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

          def import_row_data(origin_datas, row_num, textfile, sheet, numbering, auto_numbering, not_set_serial_number, external_resource)
            logger.info "import start row_num=#{row_num}"
        
            sheet_name = sheet.excelx_sheet
            with_import_message(textfile) do |res|
        Severity: Minor
        Found in lib/enju_trunk/resourceadapter/resource_import.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 field has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def field
              return @field if @field
        
              if @excelx
                field_row_num = article_sheet? ? ResourceImport::ARTICLE_HEADER_ROW : ResourceImport::BOOK_HEADER_ROW
        Severity: Minor
        Found in lib/enju_trunk/resourceadapter/resource_import.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 field_index_set has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def field_index_set(field_keys)
              names = {}
              field_keys.each do |fk|
                next unless @column_spec[fk] == :plural
                name = field_name(fk)
        Severity: Minor
        Found in lib/enju_trunk/resourceadapter/resource_import.rb - About 1 hr to fix

          Method import_row_data has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def import_row_data(origin_datas, row_num, textfile, sheet, numbering, auto_numbering, not_set_serial_number, external_resource)
          Severity: Major
          Found in lib/enju_trunk/resourceadapter/resource_import.rb - About 1 hr to fix

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

                def each_row_with_index
                  if @excelx
                    data_row_num = article_sheet? ? ResourceImport::ARTICLE_DATA_ROW : ResourceImport::BOOK_DATA_ROW
                    data_row_num.upto(@excelx.last_row(@excelx_sheet)) do |row_num|
                      yield(@excelx.row(row_num, @excelx_sheet), row_num)
            Severity: Minor
            Found in lib/enju_trunk/resourceadapter/resource_import.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 create_import_start_message has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def create_import_start_message(sheet, resource_import_textfile)
                sheet_name = sheet.excelx_sheet
                with_import_message(resource_import_textfile, true) do |res|
                  res.extraparams = "{'sheet'=>'#{sheet_name}'}" if sheet_name
                  res.body        = sheet.field.keys.join("\t")
            Severity: Minor
            Found in lib/enju_trunk/resourceadapter/resource_import.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

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

              def fix_data(cell)
                return nil unless cell
                cell = cell.to_s.strip
            
                if cell.match(/^[0-9]+\.0$/)
            Severity: Minor
            Found in lib/enju_trunk/resourceadapter/resource_import.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

            Avoid too many return statements within this method.
            Open

                  return cell.to_s
            Severity: Major
            Found in lib/enju_trunk/resourceadapter/resource_import.rb - About 30 mins to fix

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

                  def initialize(&block)
                    @field = nil
                    @rows = nil
                    @excelx = nil
                    @excelx_sheet = nil
              Severity: Minor
              Found in lib/enju_trunk/resourceadapter/resource_import.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

              There are no issues that match your filters.

              Category
              Status