MiraitSystems/enju_trunk

View on GitHub
app/models/resource_import_file.rb

Summary

Maintainability
F
6 days
Test Coverage

Method import has a Cognitive Complexity of 69 (exceeds 5 allowed). Consider refactoring.
Open

  def import
    num = {:manifestation_imported => 0, :item_imported => 0, :manifestation_found => 0, :item_found => 0, :failed => 0}
    row_num = 2
    rows = open_import_file
    field = rows.first
Severity: Minor
Found in app/models/resource_import_file.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

File resource_import_file.rb has 543 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ResourceImportFile < ActiveRecord::Base
  attr_accessible :resource_import, :edit_mode
  include ImportFile
  default_scope :order => 'id DESC'
  scope :not_imported, where(:state => 'pending', :imported_at => nil)
Severity: Major
Found in app/models/resource_import_file.rb - About 1 day to fix

    Method modify has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
    Open

      def modify
        rows = open_import_file
        row_num = 2
        field = rows.first
        rows.each do |row|
    Severity: Minor
    Found in app/models/resource_import_file.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 import has 125 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def import
        num = {:manifestation_imported => 0, :item_imported => 0, :manifestation_found => 0, :item_found => 0, :failed => 0}
        row_num = 2
        rows = open_import_file
        field = rows.first
    Severity: Major
    Found in app/models/resource_import_file.rb - About 5 hrs to fix

      Method fetch has 103 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def fetch(row, options = {:edit_mode => 'create'})
          shelf = Shelf.where(:name => row['shelf'].to_s.strip).first || Shelf.web
          case options[:edit_mode]
          when 'create'
            manifestation = nil
      Severity: Major
      Found in app/models/resource_import_file.rb - About 4 hrs to fix

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

          def fetch(row, options = {:edit_mode => 'create'})
            shelf = Shelf.where(:name => row['shelf'].to_s.strip).first || Shelf.web
            case options[:edit_mode]
            when 'create'
              manifestation = nil
        Severity: Minor
        Found in app/models/resource_import_file.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 modify has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def modify
            rows = open_import_file
            row_num = 2
            field = rows.first
            rows.each do |row|
        Severity: Minor
        Found in app/models/resource_import_file.rb - About 1 hr to fix

          Method import_series_statement has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def import_series_statement(row)
              issn = nil
              if row['issn'].present?
                issn = Lisbn.new(row['issn'].to_s)
              end
          Severity: Minor
          Found in app/models/resource_import_file.rb - About 1 hr to fix

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

              def self.import(id = nil)
                if !id.nil?
                  file = ResourceImportFile.find(id) rescue nil
                  file.import_start unless file.nil?
                else
            Severity: Minor
            Found in app/models/resource_import_file.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 import_series_statement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def import_series_statement(row)
                issn = nil
                if row['issn'].present?
                  issn = Lisbn.new(row['issn'].to_s)
                end
            Severity: Minor
            Found in app/models/resource_import_file.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 open_import_file has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def open_import_file
                tempfile = Tempfile.new('agent_import_file')
                if Setting.uploaded_file.storage == :s3
                  uploaded_file_path = open(self.resource_import.expiring_url(10)).path
                else
            Severity: Minor
            Found in app/models/resource_import_file.rb - About 1 hr to fix

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

                def find_series_statement(row)
                  issn = nil
                  if row['issn'].present?
                    issn = Lisbn.new(row['issn'].to_s)
                  end
              Severity: Minor
              Found in app/models/resource_import_file.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

                      rescue ActiveRecord::RecordInvalid  => e
                        import_result.error_msg = "FAIL[#{row_num}]: fail save manifestation. (record invalid) #{e.message}"
                        Rails.logger.error "FAIL[#{row_num}]: fail save manifestation. (record invalid) #{e.message}"
                        Rails.logger.error "FAIL[#{row_num}]: #{$@}"
                        manifestation = nil
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 50 mins to fix
              app/models/resource_import_file.rb on lines 133..147

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

              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

                      rescue ActiveRecord::StatementInvalid => e
                        import_result.error_msg = "FAIL[#{row_num}]: fail save manifestation. (statement invalid) #{e.message}"
                        Rails.logger.error "FAIL[#{row_num}]: fail save manifestation. (statement invalid) #{e.message}"
                        Rails.logger.error "FAIL[#{row_num}]: #{$@}"
                        manifestation = nil
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 50 mins to fix
              app/models/resource_import_file.rb on lines 126..147

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

              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

                      rescue EnjuNdl::InvalidIsbn
                        import_result.error_msg = "FAIL[#{row_num}]: "+I18n.t('resource_import_file.invalid_isbn', :isbn => isbn)
                        Rails.logger.error "FAIL[#{row_num}]: import_isbn catch EnjuNdl::InvalidIsbn isbn: #{isbn}"
                        manifestation = nil
                        num[:failed] += 1
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 35 mins to fix
              app/models/resource_import_file.rb on lines 120..125

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

              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

                      rescue EnjuNdl::RecordNotFound
                        import_result.error_msg = "FAIL[#{row_num}]: "+I18n.t('resource_import_file.record_not_found', :isbn => isbn)
                        Rails.logger.error "FAIL[#{row_num}]: import_isbn catch EnjuNdl::RecordNotFound isbn: #{isbn}"
                        manifestation = nil
                        num[:failed] += 1
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 35 mins to fix
              app/models/resource_import_file.rb on lines 114..119

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

              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

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

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

                state_machine :initial => :pending do
                  event :sm_start do
                    transition [:pending, :started] => :started
                  end
              
              
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 25 mins to fix
              app/models/agent_import_file.rb on lines 23..34

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

              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

                if Setting.uploaded_file.storage == :s3
                  has_attached_file :resource_import, :storage => :s3, :s3_credentials => "#{Rails.root.to_s}/config/s3.yml",
                    :path => "resource_import_files/:id/:filename",
                    :s3_permissions => :private
                else
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 20 mins to fix
              app/models/agent_import_file.rb on lines 8..14

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

              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 4 locations. Consider refactoring.
              Open

                def set_digest(options = {:type => 'sha1'})
                  if File.exists?(resource_import.queued_for_write[:original])
                    self.file_hash = Digest::SHA1.hexdigest(File.open(resource_import.queued_for_write[:original].path, 'rb').read)
              Severity: Minor
              Found in app/models/resource_import_file.rb and 3 other locations - About 20 mins to fix
              app/models/agent_import_file.rb on lines 37..39
              app/models/picture_file.rb on lines 28..30
              app/models/resource_import_textfile.rb on lines 43..45

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

              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

                  if !id.nil?
                    file = ResourceImportFile.find(id) rescue nil
                    file.import_start unless file.nil?
                  else
                    ResourceImportFile.not_imported.each do |file|
              Severity: Minor
              Found in app/models/resource_import_file.rb and 1 other location - About 15 mins to fix
              app/models/agent_import_file.rb on lines 158..163

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

              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