daddyz/phonelib

View on GitHub

Showing 15 of 214 total issues

Class Phone has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Phone
    # @!attribute [r] original
    # @return [String] original phone number passed for parsing
    attr_reader :original
    # @!attribute [r] extension
Severity: Minor
Found in lib/phonelib/phone.rb - About 2 hrs to fix

    File core.rb has 251 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Phonelib
      # main module that includes all basic data and methods
      module Core
        # @private variable will include hash with data for validation
        @@phone_data = nil
    Severity: Minor
    Found in lib/phonelib/core.rb - About 2 hrs to fix

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

          def load_data
            data_file = "#{File.dirname(__FILE__)}/../../#{FILE_MAIN_DATA}"
            default_data = Marshal.load(File.binread(data_file))
            if override_phone_data
              override_data_file = Marshal.load(File.binread(override_phone_data))
      Severity: Minor
      Found in lib/phonelib/core.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 international has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def international(formatted = true, prefix = '+')
            prefix = formatted if formatted.is_a?(String)
            return nil if sanitized.empty?
            return "#{prefix}#{country_prefix_or_not}#{sanitized}" unless valid?
            return "#{prefix}#{country_code}#{@national_number}" unless formatted
      Severity: Minor
      Found in lib/phonelib/phone_formatter.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 ext_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def ext_data
            return @ext_data if defined?(@ext_data) && @ext_data
      
            result = default_ext_data
            return result unless possible?
      Severity: Minor
      Found in lib/phonelib/phone_extended_data.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 area_code_possible? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def area_code_possible?
            return false if impossible?
      
            # has national prefix
            return false unless @data[country][Core::NATIONAL_PREFIX] || country == 'IT'
      Severity: Minor
      Found in lib/phonelib/phone_formatter.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 national has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def national(formatted = true)
            return @national_number unless valid?
            format_match, format_string = formatting_data
      
            if format_match
      Severity: Minor
      Found in lib/phonelib/phone_formatter.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 detect_and_parse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def detect_and_parse(phone, country)
            result = {}
            Phonelib.phone_data.each do |key, data|
              parsed = parse_single_country(phone, data)
              if (!Phonelib.strict_double_prefix_check || key == country) && double_prefix_allowed?(data, phone, parsed && parsed[key])
      Severity: Minor
      Found in lib/phonelib/phone_analyzer.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 raw_national has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def raw_national
            return nil if sanitized.nil? || sanitized.empty?
            if valid?
              @national_number
            elsif country_code && sanitized.start_with?(country_code)
      Severity: Minor
      Found in lib/phonelib/phone_formatter.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 hash_from_xml has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def hash_from_xml(data, type)
            hash = {}
            case type
            when :attributes
              data.attributes.each do |k, v|
      Severity: Minor
      Found in lib/phonelib/data_importer_helper.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 add_additional_regex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def add_additional_regex(country, type, national_regex)
            return unless Phonelib::Core::TYPES_DESC.keys.include?(type.to_sym)
            return unless national_regex.is_a?(String)
            @@phone_data = nil
            @@additional_regexes[country.to_s.upcase] ||= {}
      Severity: Minor
      Found in lib/phonelib/core.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 get_ext_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_ext_name(names_key, id_key)
            return nil unless ext_data[id_key]
      
            res = Phonelib.phone_ext_data[names_key][ext_data[id_key]]
            return nil unless res
      Severity: Minor
      Found in lib/phonelib/phone_extended_data.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 fill_possible_to_types_if_nil has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def fill_possible_to_types_if_nil(result)
              result[:types].each do |type, data|
                if data[Core::VALID_PATTERN] && !data[Core::POSSIBLE_PATTERN]
                  result[:types][type][Core::POSSIBLE_PATTERN] = case type
                        when Core::GENERAL
      Severity: Minor
      Found in lib/phonelib/data_importer.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize(phone, country = nil)
            @original, @extension = separate_extension(phone.to_s)
            @extension.gsub!(/[^0-9]/, '') if @extension
      
            if sanitized.empty?
      Severity: Minor
      Found in lib/phonelib/phone.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 better_result has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def better_result(base_result, result = nil)
            base_result ||= {}
            return base_result unless result
      
            return result unless base_result.values.find { |e| e[:possible].any? }
      Severity: Minor
      Found in lib/phonelib/phone_analyzer.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

      Severity
      Category
      Status
      Source
      Language