MiraitSystems/enju_trunk

View on GitHub
app/models/item.rb

Summary

Maintainability
F
2 wks
Test Coverage

File item.rb has 1307 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require EnjuTrunkFrbr::Engine.root.join('app', 'models', 'item')
require EnjuTrunkCirculation::Engine.root.join('app', 'models', 'item') if Setting.operation
require EnjuTrunkOrder::Engine.root.join('app', 'models', 'item') if defined? EnjuTrunkOrder
class Item < ActiveRecord::Base
  extend ActiveRecordExtension
Severity: Major
Found in app/models/item.rb - About 3 days to fix

    Method export_removing_list has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.export_removing_list(out_dir, file_type = nil)
        raise "invalid parameter: no path" if out_dir.nil? || out_dir.length < 1
        tsv_file = out_dir + "removing_list.tsv"
        pdf_file = out_dir + "removing_list.pdf"
        logger.info "output removing_list tsv: #{tsv_file} pdf: #{pdf_file}"
    Severity: Minor
    Found in app/models/item.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 make_item_register_pdf has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.make_item_register_pdf(pdf_file, items, list_title = nil)
        report = EnjuTrunk.new_report('item_register.tlf')
        report.events.on :page_create do |e|
          e.page.item(:page).value(e.page.no)
        end
    Severity: Minor
    Found in app/models/item.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

    Class Item has 60 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Item < ActiveRecord::Base
      extend ActiveRecordExtension
      attr_accessible :library_id, :shelf_id, :checkout_type_id, :circulation_status_id,
                      :retention_period_id, :call_number, :bookstore_id, :price, :price_string, :url,
                      :include_supplements, :use_restriction_id, :required_role_id,
    Severity: Major
    Found in app/models/item.rb - About 1 day to fix

      Method make_audio_list_tsv has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.make_audio_list_tsv(tsvfile, items)
          columns = [
            [:library, 'activerecord.models.library'],
            [:carrier_type, 'activerecord.models.carrier_type'],
            [:shelf, 'activerecord.models.shelf'],
      Severity: Minor
      Found in app/models/item.rb - About 5 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 make_item_register_tsv has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.make_item_register_tsv(tsvfile, items)
          columns = [
            [:bookstore, 'activerecord.models.bookstore'],
            ['item_identifier', 'activerecord.attributes.item.item_identifier'],
            ['acquired_at_string', 'activerecord.attributes.item.acquired_at_string'],
      Severity: Minor
      Found in app/models/item.rb - About 5 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 make_catalog_pdf has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.make_catalog_pdf(pdf_file, manifestations, list_title = nil)
          report = EnjuTrunk.new_report("#{list_title}.tlf")
          #report page
          report.events.on :page_create do |e|
            e.page.item(:page).value(e.page.no)
      Severity: Minor
      Found in app/models/item.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 export_removing_list has 94 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.export_removing_list(out_dir, file_type = nil)
          raise "invalid parameter: no path" if out_dir.nil? || out_dir.length < 1
          tsv_file = out_dir + "removing_list.tsv"
          pdf_file = out_dir + "removing_list.pdf"
          logger.info "output removing_list tsv: #{tsv_file} pdf: #{pdf_file}"
      Severity: Major
      Found in app/models/item.rb - About 3 hrs to fix

        Method make_export_series_statements_latest_list_tsv has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_series_statements_latest_list_tsv(items)
            data = String.new
            data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
        
            columns = [
        Severity: Minor
        Found in app/models/item.rb - About 3 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 make_export_series_statements_list_pdf has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_series_statements_list_pdf(items, acquired_at)
            return false if items.blank?
            report = EnjuTrunk.new_report('series_statements_list')
        
            report.events.on :page_create do |e|
        Severity: Minor
        Found in app/models/item.rb - About 3 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 make_export_series_statements_latest_list_pdf has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_series_statements_latest_list_pdf(items)
            return false if items.blank?
            report = EnjuTrunk.new_report('series_statements_latest_list')
        
            report.events.on :page_create do |e|
        Severity: Minor
        Found in app/models/item.rb - About 3 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 make_export_removed_list_pdf has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_removed_list_pdf(items)
            return false if items.blank?
            report = EnjuTrunk.new_book_term('removed_list')
        
            report.events.on :page_create do |e|
        Severity: Minor
        Found in app/models/item.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 make_export_new_book_list_pdf has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_new_book_list_pdf(items)
            return false if items.blank?
            report = EnjuTrunk.new_report('new_book_list')
        
            report.events.on :page_create do |e|
        Severity: Minor
        Found in app/models/item.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 is_original? has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def is_original?
            if self.rank == 0
              manifestation = nil
              if self.manifestation
                manifestation = self.manifestation
        Severity: Minor
        Found in app/models/item.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 check_price has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def check_price
            record = Expense.where(:item_id => self.id).order("id DESC").first
            begin
              unless record.nil?
                record.acquired_at_ym = select_acquired_at
        Severity: Minor
        Found in app/models/item.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 make_export_item_list_pdf has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_item_list_pdf(items, filename)
            return false if items.blank?
            report = EnjuTrunk.new_book_list('item_list')
        
            report.events.on :page_create do |e|
        Severity: Minor
        Found in app/models/item.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 make_export_new_item_list_pdf has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.make_export_new_item_list_pdf(items)
            return false if items.blank?
            report = EnjuTrunk.new_book_list('new_item_list')
        
            report.events.on :page_create do |e|
        Severity: Minor
        Found in app/models/item.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 make_item_register_tsv has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.make_item_register_tsv(tsvfile, items)
            columns = [
              [:bookstore, 'activerecord.models.bookstore'],
              ['item_identifier', 'activerecord.attributes.item.item_identifier'],
              ['acquired_at_string', 'activerecord.attributes.item.acquired_at_string'],
        Severity: Major
        Found in app/models/item.rb - About 2 hrs to fix

          Method make_audio_list_tsv has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.make_audio_list_tsv(tsvfile, items)
              columns = [
                [:library, 'activerecord.models.library'],
                [:carrier_type, 'activerecord.models.carrier_type'],
                [:shelf, 'activerecord.models.shelf'],
          Severity: Major
          Found in app/models/item.rb - About 2 hrs to fix

            Method make_audio_list_pdf has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.make_audio_list_pdf(pdf_file, items)
                filename = I18n.t('item_register.audio_list')
                report = EnjuTrunk.new_item_list('item_list')
            
                report.events.on :page_create do |e|
            Severity: Minor
            Found in app/models/item.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

            Consider simplifying this complex logical expression.
            Open

                  if items.nil? || items.size < 1
                    logger.warn "item data is empty"
                  else
                    items.each do |item|
                      row = []
            Severity: Critical
            Found in app/models/item.rb - About 2 hrs to fix

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

                def self.make_export_series_statements_list_tsv(items, acquired_at)
                  data = String.new
                  data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
              
                  # set term
              Severity: Minor
              Found in app/models/item.rb - About 1 hr to fix

                Method excel_worksheet_value has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def excel_worksheet_value(ws_type, ws_col, sep_flg, ccount)
                    helper = Object.new
                    helper.extend(ItemsHelper)
                    helper.instance_eval { def t(*a) I18n.t(*a) end } # NOTE: ItemsHelper#i18n_rankの中でtを呼び出しているが、ヘルパーを直接利用しようとするとRedCloth由来のtが見えてしまうため、その回避策
                    val = nil
                Severity: Minor
                Found in app/models/item.rb - About 1 hr to fix

                  Method make_export_removed_list_tsv has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.make_export_removed_list_tsv(items)
                      data = String.new
                      data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                  
                      columns = [
                  Severity: Minor
                  Found in app/models/item.rb - About 1 hr to fix

                    Method make_export_new_item_list_tsv has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def self.make_export_new_item_list_tsv(items)
                        data = String.new
                        data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                    
                        # set term
                    Severity: Minor
                    Found in app/models/item.rb - About 1 hr to fix

                      Method make_item_register_pdf has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        def self.make_item_register_pdf(pdf_file, items, list_title = nil)
                          report = EnjuTrunk.new_report('item_register.tlf')
                          report.events.on :page_create do |e|
                            e.page.item(:page).value(e.page.no)
                          end
                      Severity: Minor
                      Found in app/models/item.rb - About 1 hr to fix

                        Method make_export_new_book_list_tsv has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def self.make_export_new_book_list_tsv(items)
                            data = String.new
                            data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                        
                            # set term
                        Severity: Minor
                        Found in app/models/item.rb - About 1 hr to fix

                          Method make_export_series_statements_latest_list_tsv has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def self.make_export_series_statements_latest_list_tsv(items)
                              data = String.new
                              data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                          
                              columns = [
                          Severity: Minor
                          Found in app/models/item.rb - About 1 hr to fix

                            Method make_export_item_list_tsv has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              def self.make_export_item_list_tsv(items)
                                data = String.new
                                data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                                columns = [
                                  [:library, 'activerecord.models.library'],
                            Severity: Minor
                            Found in app/models/item.rb - About 1 hr to fix

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

                                def excel_worksheet_value(ws_type, ws_col, sep_flg, ccount)
                                  helper = Object.new
                                  helper.extend(ItemsHelper)
                                  helper.instance_eval { def t(*a) I18n.t(*a) end } # NOTE: ItemsHelper#i18n_rankの中でtを呼び出しているが、ヘルパーを直接利用しようとするとRedCloth由来のtが見えてしまうため、その回避策
                                  val = nil
                              Severity: Minor
                              Found in app/models/item.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 make_export_removed_list_tsv has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                              Open

                                def self.make_export_removed_list_tsv(items)
                                  data = String.new
                                  data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                              
                                  columns = [
                              Severity: Minor
                              Found in app/models/item.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 check_price has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                def check_price
                                  record = Expense.where(:item_id => self.id).order("id DESC").first
                                  begin
                                    unless record.nil?
                                      record.acquired_at_ym = select_acquired_at
                              Severity: Minor
                              Found in app/models/item.rb - About 1 hr to fix

                                Method make_catalog_pdf has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  def self.make_catalog_pdf(pdf_file, manifestations, list_title = nil)
                                    report = EnjuTrunk.new_report("#{list_title}.tlf")
                                    #report page
                                    report.events.on :page_create do |e|
                                      e.page.item(:page).value(e.page.no)
                                Severity: Minor
                                Found in app/models/item.rb - About 1 hr to fix

                                  Method make_export_series_statements_list_pdf has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                    def self.make_export_series_statements_list_pdf(items, acquired_at)
                                      return false if items.blank?
                                      report = EnjuTrunk.new_report('series_statements_list')
                                  
                                      report.events.on :page_create do |e|
                                  Severity: Minor
                                  Found in app/models/item.rb - About 1 hr to fix

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

                                      def check_remove_item
                                        if self.circulation_status_id == CirculationStatus.where(name: 'Removed').first.try(:id) or self.remove_reason
                                          self.removed_at = Time.zone.now if self.removed_at.nil?
                                          manifestation = nil
                                          if self.manifestation
                                    Severity: Minor
                                    Found in app/models/item.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 make_export_new_book_list_pdf has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                      def self.make_export_new_book_list_pdf(items)
                                        return false if items.blank?
                                        report = EnjuTrunk.new_report('new_book_list')
                                    
                                        report.events.on :page_create do |e|
                                    Severity: Minor
                                    Found in app/models/item.rb - About 1 hr to fix

                                      Method make_export_series_statements_list_tsv has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                        def self.make_export_series_statements_list_tsv(items, acquired_at)
                                          data = String.new
                                          data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                                      
                                          # set term
                                      Severity: Minor
                                      Found in app/models/item.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 perform has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                          def perform
                                            fn = "#{file_name}.#{file_type}"
                                            user_file = UserFile.new(user)
                                            url = nil
                                            logger.error "SQL start at #{Time.now}"
                                      Severity: Minor
                                      Found in app/models/item.rb - About 1 hr to fix

                                        Method make_export_new_item_list_pdf has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                          def self.make_export_new_item_list_pdf(items)
                                            return false if items.blank?
                                            report = EnjuTrunk.new_book_list('new_item_list')
                                        
                                            report.events.on :page_create do |e|
                                        Severity: Minor
                                        Found in app/models/item.rb - About 1 hr to fix

                                          Method perform has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                          Open

                                              def perform
                                                user_file = UserFile.new(user)
                                          
                                                # get data
                                                query = Marshal.load(dumped_query)
                                          Severity: Minor
                                          Found in app/models/item.rb - About 1 hr to fix

                                            Method make_audio_list_pdf has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                              def self.make_audio_list_pdf(pdf_file, items)
                                                filename = I18n.t('item_register.audio_list')
                                                report = EnjuTrunk.new_item_list('item_list')
                                            
                                                report.events.on :page_create do |e|
                                            Severity: Minor
                                            Found in app/models/item.rb - About 1 hr to fix

                                              Consider simplifying this complex logical expression.
                                              Open

                                                    if items.nil? || items.size < 1
                                                      logger.warn "item data is empty"
                                                    else
                                                      items.each do |item|
                                                        row = []
                                              Severity: Major
                                              Found in app/models/item.rb - About 1 hr to fix

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

                                                    def perform
                                                      user_file = UserFile.new(user)
                                                
                                                      # get data
                                                      query = Marshal.load(dumped_query)
                                                Severity: Minor
                                                Found in app/models/item.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 initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
                                                Open

                                                    def initialize(job_name, file_name, file_type, method, dumped_query, args, user)
                                                Severity: Major
                                                Found in app/models/item.rb - About 50 mins to fix

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

                                                      def initialize(job_name, file_name, file_type, method, args, user)
                                                  Severity: Minor
                                                  Found in app/models/item.rb - About 45 mins to fix

                                                    Method export_item_register has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                    Open

                                                      def self.export_item_register(type, out_dir, file_type = nil)
                                                        raise "invalid parameter: no path" if out_dir.nil? || out_dir.length < 1
                                                        tsv_file = out_dir + "item_register_#{type}.tsv"
                                                        pdf_file = out_dir + "item_register_#{type}.pdf"
                                                        logger.info "output item_register_#{type} tsv: #{tsv_file} pdf: #{pdf_file}"
                                                    Severity: Minor
                                                    Found in app/models/item.rb - About 45 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 make_export_item_list_job has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                                    Open

                                                      def self.make_export_item_list_job(file_name, file_type, method, dumped_query, args, user)
                                                    Severity: Minor
                                                    Found in app/models/item.rb - About 45 mins to fix

                                                      Avoid deeply nested control flow statements.
                                                      Open

                                                                        row << item.manifestation.date_of_publication.strftime("%Y/%m/%d") rescue ""
                                                      Severity: Major
                                                      Found in app/models/item.rb - About 45 mins to fix

                                                        Method output_catalog has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                          def self.output_catalog(type, out_dir, file_type = nil)
                                                            raise "invalid parameter: no path" if out_dir.nil? || out_dir.length < 1
                                                            pdf_file = out_dir + "#{type}_catalog.pdf"
                                                            logger.info "output #{type}_catalog  pdf: #{pdf_file}"
                                                        FileUtils.mkdir_p(out_dir) unless FileTest.exist?(out_dir)
                                                        Severity: Minor
                                                        Found in app/models/item.rb - About 45 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 make_export_register_job has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                        Open

                                                          def self.make_export_register_job(file_name, file_type, method, args, user)
                                                        Severity: Minor
                                                        Found in app/models/item.rb - About 35 mins to fix

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

                                                            def self.make_export_new_item_list_tsv(items)
                                                              data = String.new
                                                              data << "\xEF\xBB\xBF".force_encoding("UTF-8") + "\n"
                                                          
                                                              # set term
                                                          Severity: Minor
                                                          Found in app/models/item.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 export_audio_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                            def self.export_audio_list(out_dir, file_type = nil)
                                                              raise "invalid parameter: no path" if out_dir.nil? || out_dir.length < 1
                                                              tsv_file = out_dir + "audio_list.tsv"
                                                              pdf_file = out_dir + "audio_list.pdf"
                                                              logger.info "output audio_list tsv: #{tsv_file} pdf: #{pdf_file}"
                                                          Severity: Minor
                                                          Found in app/models/item.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

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

                                                            def has_view_role?(current_role_id)
                                                              current_role_id = Role.default_role.id unless current_role_id
                                                              if self.required_role_id <= current_role_id && (self.shelf.required_role_id.nil? || self.shelf.required_role_id <= current_role_id)
                                                                return TRUE
                                                              else
                                                          Severity: Minor
                                                          Found in app/models/item.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

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

                                                              items.each do |item|
                                                                report.page.list(:list).add_row do |row|
                                                                  row.item(:library).value(item.shelf.library.display_name.localize) if item.shelf && item.shelf.library
                                                                  row.item(:acquired_at).value(item.acquired_at_string) if item.acquired_at_string
                                                                  row.item(:bookstore).value(item.bookstore.name) if item.bookstore
                                                          Severity: Major
                                                          Found in app/models/item.rb and 1 other location - About 2 hrs to fix
                                                          app/models/item.rb on lines 1173..1182

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

                                                          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

                                                              items.each do |item|
                                                                report.page.list(:list).add_row do |row|
                                                                  row.item(:library).value(item.shelf.library.display_name.localize) if item.shelf && item.shelf.library
                                                                  row.item(:acquired_at).value(item.acquired_at_string) if item.acquired_at_string
                                                                  row.item(:bookstore).value(item.bookstore.name) if item.bookstore
                                                          Severity: Major
                                                          Found in app/models/item.rb and 1 other location - About 2 hrs to fix
                                                          app/models/item.rb on lines 1255..1264

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

                                                          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

                                                                report.page.list(:list).add_row do |row|
                                                                  row.item(:library).value(item.shelf.library.display_name.localize) if item.shelf && item.shelf.library
                                                                  row.item(:carrier_type).value(item.manifestation.carrier_type.display_name.localize) if item.manifestation && item.manifestation.carrier_type
                                                                  row.item(:shelf).value(item.shelf.display_name) if item.shelf
                                                                  row.item(:ndc).value(item.manifestation.ndc) if item.manifestation
                                                          Severity: Major
                                                          Found in app/models/item.rb and 1 other location - About 2 hrs to fix
                                                          app/models/item.rb on lines 864..871

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

                                                          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

                                                                report.page.list(:list).add_row do |row|
                                                                  row.item(:library).value(item.shelf.library.display_name.localize) if item.shelf && item.shelf.library
                                                                  row.item(:carrier_type).value(item.manifestation.carrier_type.display_name.localize) if item.manifestation && item.manifestation.carrier_type
                                                                  row.item(:shelf).value(item.shelf.display_name) if item.shelf
                                                                  row.item(:ndc).value(item.manifestation.ndc) if item.manifestation
                                                          Severity: Major
                                                          Found in app/models/item.rb and 1 other location - About 2 hrs to fix
                                                          app/models/item.rb on lines 834..841

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

                                                          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

                                                              columns = [
                                                                [:library, 'activerecord.models.library'],
                                                                ['acquired_at', 'activerecord.attributes.item.acquired_at'],
                                                                [:bookstore, 'activerecord.models.bookstore'],
                                                                ['item_identifier', 'activerecord.attributes.item.item_identifier'],
                                                          Severity: Minor
                                                          Found in app/models/item.rb and 1 other location - About 15 mins to fix
                                                          app/models/item.rb on lines 1283..1292

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

                                                          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

                                                              columns = [
                                                                [:library, 'activerecord.models.library'],
                                                                ['acquired_at_string', 'activerecord.attributes.item.acquired_at_string'],
                                                                [:bookstore, 'activerecord.models.bookstore'],
                                                                ['item_identifier', 'activerecord.attributes.item.item_identifier'],
                                                          Severity: Minor
                                                          Found in app/models/item.rb and 1 other location - About 15 mins to fix
                                                          app/models/item.rb on lines 1192..1201

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

                                                          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