Showing 40 of 40 total issues

Class Metadata has 39 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Metadata
    class NilContent
      def self.content
        nil
      end
Severity: Minor
Found in lib/gepub/metadata.rb - About 5 hrs to fix

    File book.rb has 376 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'rubygems'
    require 'nokogiri'
    require 'zip'
    require 'fileutils'
    
    
    Severity: Minor
    Found in lib/gepub/book.rb - About 5 hrs to fix

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

          def nav_doc(title = 'Table of Contents')
            # handle cascaded toc
            start_level = @toc && !@toc.empty? && @toc[0][:level] || 1
            stacked_toc = {level: start_level, tocs: [] }
            @toc.inject(stacked_toc) do |current_stack, toc_entry|
      Severity: Minor
      Found in lib/gepub/book.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 nav_doc has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def nav_doc(title = 'Table of Contents')
            # handle cascaded toc
            start_level = @toc && !@toc.empty? && @toc[0][:level] || 1
            stacked_toc = {level: start_level, tocs: [] }
            @toc.inject(stacked_toc) do |current_stack, toc_entry|
      Severity: Major
      Found in lib/gepub/book.rb - About 2 hrs to fix

        Class Book has 25 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class Book
            include InspectMixin
        
            MIMETYPE='mimetype'
            MIMETYPE_CONTENTS='application/epub+zip'
        Severity: Minor
        Found in lib/gepub/book.rb - About 2 hrs to fix

          File metadata.rb has 282 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          require 'rubygems'
          require 'nokogiri'
          require 'time'
          
          module GEPUB
          Severity: Minor
          Found in lib/gepub/metadata.rb - About 2 hrs to fix

            Method guess_content_property has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
            Open

                def guess_content_property
                  if File.extname(self.href) =~ /.x?html/ && @attributes['media-type'] === 'application/xhtml+xml'
                    @attributes['properties'] ||= []
                    parsed = Nokogiri::XML::Document.parse(@content)
                    return unless parsed.root.node_name === "html"
            Severity: Minor
            Found in lib/gepub/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

            Class ResourceBuilder has 23 methods (exceeds 20 allowed). Consider refactoring.
            Open

              class ResourceBuilder
                include BuilderMixin
                class ResourceItem
                  attr_reader :item
                  def initialize(item)
            Severity: Minor
            Found in lib/gepub/resource_builder.rb - About 2 hrs to fix

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

                class Package
                  include XMLUtil, DSLUtil
                  include InspectMixin
              
                  extend Forwardable
              Severity: Minor
              Found in lib/gepub/package.rb - About 2 hrs to fix

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

                    def opf_xml
                      if version.to_f < 3.0 || @epub_backward_compat
                        spine.toc  ||= 'ncx'
                        if @metadata.oldstyle_meta.select {
                          |meta|
                Severity: Minor
                Found in lib/gepub/package.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 write_toc has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                      def write_toc xml_doc, tocs
                        return if tocs.empty?
                        xml_doc.ol {
                          tocs.each {
                            |x|
                Severity: Minor
                Found in lib/gepub/book.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

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

                    def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil,
                                  title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
                                  lang: nil, alternates: {})
                      if deprecated_id
                        warn 'second argument for add_title is deprecated. use id: instead'
                Severity: Major
                Found in lib/gepub/metadata_add.rb and 1 other location - About 1 hr to fix
                lib/gepub/metadata_add.rb on lines 106..121

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

                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

                    def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil,
                                        title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
                                        lang: nil, alternates: {}) 
                      if deprecated_id
                        warn 'second argument for add_contributor is deprecated. use id: instead'
                Severity: Major
                Found in lib/gepub/metadata_add.rb and 1 other location - About 1 hr to fix
                lib/gepub/metadata_add.rb on lines 51..66

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

                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

                Method lastmodified has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    def lastmodified(date=UNASSIGNED)
                      if unassigned?(date)
                        ret = (@content_nodes['meta'] ||=[]).select {
                          |meta|
                          meta['property'] == 'dcterms:modified'
                Severity: Minor
                Found in lib/gepub/metadata.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 method_missing has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    def method_missing(name, *args, &block)
                      if Array === @last_defined_item &&
                          @last_defined_item.size > 0 &&
                          @last_defined_item[0].respond_to?(name.to_sym)
                
                
                Severity: Minor
                Found in lib/gepub/builder_mixin.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 to_xml has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    def to_xml(builder, id_pool, ns = nil, additional_attr = {}, opf_version = '3.0')
                      additional_attr ||= {}
                      if @refiners.size > 0 && opf_version.to_f >= 3.0
                        @attributes['id'] = id_pool.generate_key(:prefix => name) if @attributes['id'].nil?
                      end
                Severity: Minor
                Found in lib/gepub/meta.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 opf_xml has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def opf_xml
                      if version.to_f < 3.0 || @epub_backward_compat
                        spine.toc  ||= 'ncx'
                        if @metadata.oldstyle_meta.select {
                          |meta|
                Severity: Minor
                Found in lib/gepub/package.rb - About 1 hr to fix

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

                      def ncx_xml
                        builder = Nokogiri::XML::Builder.new {
                          |xml|
                          xml.ncx('xmlns' => 'http://www.daisy.org/z3986/2005/ncx/', 'version' => '2005-1') {
                            xml.head {
                  Severity: Minor
                  Found in lib/gepub/book.rb - About 1 hr to fix

                    Method parse has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def self.parse(metadata_xml, opf_version = '3.0', id_pool = Package::IDPool.new)
                          Metadata.new(opf_version, id_pool) {
                            |metadata|
                            metadata.instance_eval {
                              @xml = metadata_xml
                    Severity: Minor
                    Found in lib/gepub/metadata.rb - About 1 hr to fix

                      Method guess_content_property has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def guess_content_property
                            if File.extname(self.href) =~ /.x?html/ && @attributes['media-type'] === 'application/xhtml+xml'
                              @attributes['properties'] ||= []
                              parsed = Nokogiri::XML::Document.parse(@content)
                              return unless parsed.root.node_name === "html"
                      Severity: Minor
                      Found in lib/gepub/item.rb - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language