daddyz/phonelib

View on GitHub

Showing 19 of 262 total issues

File core.rb has 273 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

    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

      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 possible?
            return "#{prefix}#{data_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 possible?
            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)
            countries_data = country_code_candidates_for(phone).flat_map { |code|
              Phonelib.data_by_country_codes[code] || []
            }
            countries_data.each_with_object({}) do |data, result|
      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 separate_extension has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def separate_extension(original)
            return [original, ''] unless Phonelib.extension_separate_symbols
      
            regex = if Phonelib.extension_separate_symbols.is_a?(Array)
                      cr("#{Phonelib.extension_separate_symbols.join('|')}")
      Severity: Minor
      Found in lib/phonelib/phone.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 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 = @@data_by_country_codes = 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 decorate_analyze_result has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def decorate_analyze_result(result)
            if result.size == 1
              result
            else
              matched_countries = country_or_default_country(nil) & result.keys
      Severity: Minor
      Found in lib/phonelib/phone_analyzer_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 country_code has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def country_code
            return @country_code if @country_code
      
            code = Phonelib.phone_data[country] && Phonelib.phone_data[country][Core::COUNTRY_CODE]
            return @country_code = code unless code == '1' && Phonelib.phone_data[country][Core::LEADING_DIGITS]
      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 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 = @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 with_replaced_national_prefix has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def with_replaced_national_prefix(phone, data)
            return phone unless data[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
            phone = phone.gsub(/^#{data[Core::COUNTRY_CODE]}/, '') if phone.start_with?(data[Core::COUNTRY_CODE]) && !data[Core::DOUBLE_COUNTRY_PREFIX_FLAG]
            pattern = cr("^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})")
            match = phone.match pattern
      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

      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 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 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 data_country_code && sanitized.start_with?(data_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 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