n7v/phonetic

View on GitHub

Showing 32 of 32 total issues

Consider simplifying this complex logical expression.
Open

      elsif !(i > 1 && w[i - 2] =~ /[BHD]/ || # e.g., 'hugh'
              i > 2 && w[i - 3] =~ /[BHD]/ || # e.g., 'bough'
              i > 3 && w[i - 4] =~ /[BH]/)    # e.g., 'broughton'
        # e.g., 'laugh', 'McLaughlin', 'cough', 'gough', 'rough', 'tough'
        if i > 2 && w[i - 3, 3] =~ /[CGLRT].U/
Severity: Major
Found in lib/phonetic/double_metaphone.rb - About 40 mins to fix

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

        def self.find_code(map, w, i, last = nil, count = 0)
    Severity: Minor
    Found in lib/phonetic/dm_soundex.rb - About 35 mins to fix

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

          def self.gen_encode(w, i, primary, secondary, code)
      Severity: Minor
      Found in lib/phonetic/double_metaphone.rb - About 35 mins to fix

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

            def self.encode_word(word, options = {})
              return '' if word.empty?
              w = word.upcase
              res = w[0]
              pg = CODE[w[0].to_sym]
        Severity: Minor
        Found in lib/phonetic/soundex.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 encode_word has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.encode_word(word, options = { trim: true })
              return if !word or word.empty?
              trim = options[:trim]
              w = word.upcase
              w.gsub!(/[^A-Z]/, '')
        Severity: Minor
        Found in lib/phonetic/nysiis.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 encode_w has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.encode_w(w, i, len, code)
              last = len - 1
              r = 1
              # can also be in middle of word
              if w[i, 2] == 'WR'
        Severity: Minor
        Found in lib/phonetic/double_metaphone.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 encode_cc has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.encode_cc(w, i, code)
              r = 0
              # 'bellocchio' but not 'bacchus'
              if w[i + 2, 1] =~ /[IEH]/ && w[i + 2, 2] != 'HU'
                # 'accident', 'accede' 'succeed'
        Severity: Minor
        Found in lib/phonetic/double_metaphone.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 ch_germanic_or_greek? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.ch_germanic_or_greek?(w, i, len)
              # germanic, greek, or otherwise 'ch' for 'kh' sound
              w[0, 4] =~ /^(V[AO]N\s|SCH)/ ||
              # 'architect but not 'arch', 'orchestra', 'orchid'
              i > 1 && w[i - 2, 6] =~ /ORCHES|ARCHIT|ORCHID/ ||
        Severity: Minor
        Found in lib/phonetic/double_metaphone.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 encode_t has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.encode_t(w, n)
              metaph = ''
              if w[n + 1, 2] =~ /I[OA]/
                metaph = 'X'
              elsif w[n + 1] == 'H'
        Severity: Minor
        Found in lib/phonetic/metaphone.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 encode_word has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.encode_word(word, options = { size: 4 })
              code_size = options[:size] || 4
              w = word.strip.upcase
              code = Code.new
              i = 0
        Severity: Minor
        Found in lib/phonetic/double_metaphone.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

            def self.encode_word(word, options = {})
              w = word.strip.downcase.gsub(/[^a-z]/, '')
              MAP.each { |r, v| w.gsub!(r, v) }
              w = w + '1' * 10
              w[0..9]
        Severity: Minor
        Found in lib/phonetic/caverphone2.rb and 1 other location - About 25 mins to fix
        lib/phonetic/caverphone.rb on lines 61..65

        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

            def self.encode_word(word, options = {})
              w = word.strip.downcase.gsub(/[^a-z]/, '')
              MAP.each { |r, v| w.gsub!(r, v) }
              w = w + '1' * 6
              w[0..5]
        Severity: Minor
        Found in lib/phonetic/caverphone.rb and 1 other location - About 25 mins to fix
        lib/phonetic/caverphone2.rb on lines 62..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 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

        Severity
        Category
        Status
        Source
        Language